使用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()进行链接跳转。

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐