1、查看安装的chrome浏览器版本

    

  2、查看版本对应的驱动

    https://sites.google.com/a/chromium.org/chromedriver/downloads

    

    

    下载后拷贝到/usr/local/bin/目录下

    结果在运行程序的时候右报错:selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    后来网上查下修改如下代码:

    

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options)

    就正常运行了

   3、完整代码

# coding=utf-8
import os
import re
from selenium import webdriver
# from pyvirtualdisplay import Display
from selenium.webdriver.chrome.options import Options
from datetime import datetime,timedelta
import time
from pyquery import PyQuery as pq
import re import datetime class consumer: def __init__(self):
#通过配置文件获取IEDriverServer.exe路径
# IEDriverServer ='C:\Program Files\Internet Explorer\IEDriverServer.exe'
# self.driver = webdriver.Ie(IEDriverServer)
# self.driver.maximize_window()
# self.driver = webdriver.PhantomJS(service_args=['--load-images=false'])
# self.driver = driver = webdriver.Chrome() chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--disable-gpu')
self.driver = webdriver.Chrome(chrome_options=chrome_options) # options = webdriver.FirefoxOptions()
# # options.set_headless()
# options.add_argument('--headless')
# options.add_argument('--disable-gpu')
# self.driver = webdriver.Firefox(firefox_options=options)
# self.driver.set_page_load_timeout(10)
# self.driver.maximize_window() # display = Display(visible=0, size=(800, 600))
# display.start()
# self.driver = webdriver.Firefox()
# self.driver.maximize_window() def WriteLog(self, message,date):
dir = os.path.join(os.getcwd(), 'consumer1')
if not os.path.exists(dir):
os.mkdir(dir)
fileName = os.path.join(dir, date + '.txt')
with open(fileName, 'a') as f:
f.write(message) # http://search.cctv.com/search.php?qtext=消费主张&type=video
def CatchData(self,url='http://search.cctv.com/search.php?qtext=%E6%B6%88%E8%B4%B9%E4%B8%BB%E5%BC%A0&type=video'):
error = ''
try:
self.driver.get(url) selenium_html = self.driver.execute_script("return document.documentElement.outerHTML")
doc = pq(selenium_html) message = '{0},{1}'.format( '标题', '时间')
filename = datetime.datetime.now().strftime('%Y-%m-%d')
self.WriteLog(message, filename)
pages = doc("div[class='page']").find("a")
# 2018-06-05 00:12:21
pattern = re.compile("\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}")
for index in range(1,6):
url = "get_data('{0}', '消费主张', 'relevance', 'video', '-1', '1', '', '20', '1')".format(index) self.driver.execute_script(url)
selenium_html = self.driver.execute_script("return document.documentElement.outerHTML")
doc = pq(selenium_html)
print(index)
try:
Elements = doc("div[class='jvedio']").find("a")
for sub in Elements.items():
title = sub.attr('title')
print(title)
ts = pattern.findall(title)
strtime = ''
if ts and len(ts) == 1:
strtime = ts[0]
if strtime:
index1 = title.index(strtime)
title = str(title[0:index1]).replace("•","") title = '\n{0},{1}'.format(title, strtime)
self.WriteLog(title, filename)
except Exception as e:
print("OS error: {0}".format(e)) except Exception as e1:
error = "ex" # python "C:\Program Files (x86)\JetBrains\PyCharm 2016.2.3\helpers\pydev\setup_cython.py" build_ext --inplace obj = consumer() obj.CatchData()
# obj.CatchContent('')
# obj.export('')

    

centos7 selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH的更多相关文章

  1. selenium使用遇到的问题(selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.)

    1.安装pip3 install selenium 2.使用browser=webdriver.Chrome()时报错 :selenium.common.exceptions.WebDriverExc ...

  2. python+selenium,打开浏览器时报selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    有一年多没写web自动化了,今天搭建环境的时候报了一个常见错误,但是处理过程有点闹心,报错就是常见的找不到驱动<selenium.common.exceptions.WebDriverExcep ...

  3. mac-webui-selenium下的webdriver selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    from selenium import webdriver def test1(): url='http://www.baidu.com' driver=webdriver.Chrome(" ...

  4. selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.

    解决办法: 把chromedriver exe文件放到python scripts目录下

  5. 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

    解决方案: 1.查看浏览器当前版本:chrome://version/. 2.到https://sites.google.com/a/chromium.org/chromedriver/downloa ...

  6. python 安装selenium首次运行错误selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH

    问题原因: 没有安装相关的支撑driver https://npm.taobao.org/mirrors/chromedriver/ 下载对应的driver 放置到python路径下

  7. 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in P

    转载 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be i ...

  8. selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 错误处理方法

    首次使用selenium webdriver,webdriver.Firefox() 报错selenium.common.exceptions.WebDriverException: Message: ...

  9. windows下使用selenium报错selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH

    问题 :执行程序代码报错: WebDriverException:Message:'geckodriver'executable needs to be in Path 或者 selenium.com ...

随机推荐

  1. poj1562 Oil Deposits(DFS)

    题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...

  2. 【WPF】生成二维码

    第一步,下载Google的ZXing类库,以便引用: BitMatrix bitMatrix; private void Button_Click_1(object sender, RoutedEve ...

  3. 牛客网 牛客练习赛43 B.Tachibana Kanade Loves Probability-快速幂加速

    链接:https://ac.nowcoder.com/acm/contest/548/B来源:牛客网 Tachibana Kanade Loves Probability 时间限制:C/C++ 1秒, ...

  4. Java反序列化漏洞之殇

    ref:https://xz.aliyun.com/t/2043 小结: 3.2.2版本之前的Apache-CommonsCollections存在该漏洞(不只该包)1.漏洞触发场景 在java编写的 ...

  5. Python导入模块-Import

    #1语法importimport module1,module2,module3,module4 #2from xx import xx 语句from module import name1,name ...

  6. Problem F: 最大公约数、最小公倍数

    Description 输入两个正整数m和n,输出m.n的最大公约数和最大公倍数.先计算最大公约数,m和n得乘积除以最大公约数,就得到了最小公倍数.其中最大公约数可以用穷举法求得,也可以用辗转相除法求 ...

  7. MySQL的max_user_connections拒绝连接的一次踩雷经验

    近期线上的数据遇到一个问题,最终原因为max_user_connections和max_connections的一个bug导致,具体过程如下 现象 前端页面不断的出现错误页面. 排查处理过程 按照数据 ...

  8. WebDriver工作原理

    http://www.cnblogs.com/timsheng/archive/2012/06/12/2546957.html 通过研究selenium-webdriver的源码,笔者发现其实webd ...

  9. MC34063组成DC-DC电路

    +VO的输出电压峰值可达2倍V_IN,-VO的输出电压可达-V_IN. 需要注意的是,3路的峰值电路不能超过1.5A,同时两路附加电源的输出功率和必须小于V_IN·I·(1-D), 其中I为主输出的电 ...

  10. 找不到原始安装光盘的佳能EOS Utility的下载和安装

    佳能EOS Utility的下载和安装   佳能很有意思,在官方网站上提供的数码相机驱动程序,只是“升级版”,而不是原始安装版.如果我有安装光盘,还去网上下载驱动干吗?解决方案:1,从佳能官方网站上下 ...