使用python模拟百度搜索“data_bug”的博客
下面根据代码一步步带你解释
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
首先我们需要加载这几个库( selenium),直接import就可以,本人使用Anaconda,里面已经自带含有这个库,不许要另外pip下载。
你需要下载驱动我这里使用的是Chrome浏览器,所以我们下载chromedriver,在网上可以下载到,将这个chromedriver.exe放在你安装chrome的文件夹下,如下:
下载的这个Chrome驱动的版本,需要查看自己Chrome浏览器的相应版本,不然不支持,运用python代码就会报错。当你上述完成后就可以运行下面的代码啦!
# 加启动配置
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')#处理异常报错
# 打开chrome浏览器驱动件
chromedriver = "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome(chromedriver,chrome_options=option)
driver.get('https://www.bai