使用 selenium可以调用 谷歌、火狐等浏览器进行爬虫的爬取,比如这段代码出现use options instead of chrome_options:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
base_url = "http://www.baidu.com/"
driver = webdriver.Chrome(chrome_options = chrome_options)
driver.get(base_url + "/")
driver.find_element_by_id("kw").send_keys("Python程序设计")
driver.find_element_by_id("su").click()
driver.save_screenshot('screen.png')
driver.close()
DeprecationWarning: use options instead of chrome_options
解决方法:
chrome_options参数是已经弃用的,被新的参数options替换了
将 chrome_options 替换为 options 即可。
修改第七行:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
base_url = "http://www.baidu.com/"
driver = webdriver.Chrome(options = chrome_options)
driver.get(base_url + "/")
driver.find_element_by_id("kw").send_keys("Python程序设计")
driver.find_element_by_id("su").click()
driver.save_screenshot('screen.png')
driver.close()
运行结果: