# 使用selenium和phantomJS浏览器获取网页内容的小演示# 导入包from selenium import webdriver# 使用selenium库里的webdriver方法调用PhantomJS浏览器实例一个浏览器的操作对象# 括号里的参数为PhantomJS浏览器在电脑里的绝对路径,这里已经添加了环境变量,所以可以省略web = webdriver.PhantomJS()#web = webdriver.PhantomJS(executable_path="./phantomjs")# 浏览器获取一个urlweb.get("https://fanyi.baidu.com/")# 保存浏览器截图web.save_screenshot("baidu.png")# 浏览器寻找一个id为括号里的名字的标签, ?????????????然后输入 hello worldweb.find_element_by_id("baidu_translate_input").send_keys("hello world")# 保存截图web.save_screenshot("baidu1.png")# 浏览器寻找一个id为括号里的名字的标签, ???????????然后点击(模拟鼠标左键)web.find_element_by_class_name("select-inner").click()# 保存截图web.save_screenshot("baidu2.png")
使用selenium和phantomJS浏览器获取网页内容的小演示
原文地址:https://www.cnblogs.com/shawone/p/10269315.html