from selenium import webdriver
from scrapy.selector import Selector
from time import sleep
chrome_opt = webdriver.ChromeOptions();
prefs ={"profile.managed_default_content_settings.images":2}
chrome_opt.add_experimental_option("prefs",prefs)
browser = webdriver.Chrome(executable_path="D:/Program Files/selenium_brower/chromedriver.exe",chrome_options=chrome_opt)
browser.get("https://www.taobao.com")
profile.managed_default_content_settings.images 意思不加载网页中的图片
在windows环境下 注意路径一定要用 / 这种
browser.find_element_by_css_selector(".Login-content input[name='username']").send_keys("13460688542")
browser.find_element_by_css_selector(".Login-content input[name='password']").send_keys("3989441qwe")
browser.find_element_by_css_selector(".Button.SignFlow-submitButton.Button--primary.Button--blue").click()
可以选择对应的css 来获取元素,send_keys对元素赋值
js = "window.scrollTo(0,document.body.scrollHeight);var lenOfpage=document.body.scrollHeight;return lenOfpage "
browser.execute_script(js)
用js的方式下拉滚动条
Selenium support for PhantomJS has been deprecated,
please use headless versions of Chrome or Firefox instead
PhantomJS 和 Chrome 官方推荐使用Chrome 浏览
t_selector = Selector(text=browser.page_source)
t_selector.css(".tm-promo-price .tm-price::text").extract()
用scrapy 解析css 感觉美滋滋
http://selenium-python.readthedocs.io/installation.html
官方讲的最详细,其他都是次要的