使用python完成模拟浏览器操作主要是使用selenium来模拟浏览器,当然还要带上浏览器的驱动比如chromedriver.exe的驱动。
一般使用selenium进行模拟操作需要注意引入一下几个类:
selenium webdriver
selenium.webdriver.common.by By
selenium.webdriver.support.ui WebDriverWait
selenium.webdriver.support expected_conditions EC
selenium.common.exceptions TimeoutException
selenium是webdrive中的东西,只要安装了selenium之后就可以了。expected_conditions可以调用防止超时的组件,防止页面没有完全加载。
browser = webdriver.Chrome(executable_path="D:/scrapytest/price_test/tools/chromedriver.exe")
这里是直接创建webdriver实例。browser.get('http://jr.jd.com/')
使用browser.get()进行链接跳转。