selenium也太好玩了吧

本小妞迷上赌 提交于 2020-02-02 10:53:59
初学爬虫,发现居然有selenium这么个东西,真的神奇噢,可惜性能差.....不过真的好玩哈哈哈
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Key
from scrapy import Selector

#设置选项(可不填)
chrome_options = Options()
chrome_options.add_argument("--disable-gpu")#防bug
#无界面
chrome_options.add_argument("--headless")
#无图
chrome_options.add_argument("blink-settings=imagesEnabled=false")

#访问
browser = webdriver.Chrome(executable_path="webdriver路径直到.exe",chrome_options=chrome_options)
browser.get("url")
sel = Selector(text=browser.page_source)
browser.close()

#点击
click_ele = browser.find_element_by_xpath("")#还可通过find_element_by_id()定位
click_ele.click()


先写这么多,详细内容我去学习一下再做总结!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!