关于安装火狐浏览器驱动的问题 阅读:1360回复:14
今天看到这个脚本https://githubacom/banhao/scrape-youtube-channel-videos-url
按步骤运行后出现,raise WebDriverException( selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home。 然后找到解决方案说是如此:https://blog.csdn.net/weixin_37185329/article/details/80493281 请问,我配置了python,在使用如下代码from selenium import webdriver browser = webdriver.Firefox() browser.get('http://baidu.com')已经可以打开火狐了,说明前面的配置都没有问题,驱动已经可以了,环境变量也没问题。 但报错是说,我没有安装谷歌浏览器的驱动,可是我用的是火狐呀,大家看看那个i项目测试说火狐可以的呀。 |
# scrape-youtube-channel-videos-url.py #_*_coding: utf-8_*_ import sys, unittest, time, datetime import urllib.request, urllib.error, urllib.parse from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import InvalidArgumentException url = sys.argv[1] channelid = url.split('/')[4] driver=webdriver.Firefox() #driver=webdriver.Chrome() driver.get(url) time.sleep(5) dt=datetime.datetime.now().strftime("%Y%m%d%H%M") height = driver.execute_script("return document.documentElement.scrollHeight") lastheight = 0 while True: if lastheight == height: break lastheight = height driver.execute_script("window.scrollTo(0, " + str(height) + ");") time.sleep(2) height = driver.execute_script("return document.documentElement.scrollHeight") user_data = driver.find_elements_by_xpath('//*[@id="video-title"]') for i in user_data: print(i.get_attribute('href')) link = (i.get_attribute('href')) f = open(channelid+'-'+dt+'.list', 'a+') f.write(link + '\n') f.close |