#PhantomJS已经不被selenium支持 但是现在好像还能用 使用的话 需要降低selenium版本
#或者使用无窗口化的火狐谷歌驱动
from selenium import webdriver
import time
#phantomjs路径
path = r\'D:\\Python\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe\'
browser = webdriver.PhantomJS(path)
#打开百度
url = "http://www.baidu.com/"
browser.get(url)
time.sleep(3)
#拍照片
browser.save_screenshot(r\'phantomjs_photo\\baidu.png\')
time.sleep(3)
#找百度input搜索框
my_input = browser.find_element_by_id(\'kw\')
#往搜索框写文字
my_input.send_keys(\'美女\')
browser.save_screenshot(r\'phantomjs_photo\\meinv.png\')
time.sleep(3)
#查找搜索按钮
button = browser.find_elements_by_class_name(\'s_btn\')[0]
button.click()
time.sleep(3)
browser.save_screenshot(r\'phantomjs_photo\\show.png\')
time.sleep(3)
browser.quit()
from selenium import webdriver
import time
#phantomjs路径
path = r\'D:\\Python\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe\'
browser = webdriver.PhantomJS(path)
url = "https://movie.douban.com/typerank?type_name=%E7%88%B1%E6%83%85&type=13&interval_id=100:90&action="
browser.get(url)
time.sleep(3)
browser.save_screenshot(r\'phantomjs_photo\\douban.png\')
#让browser执行简单的极速代码,模拟滚动到底部
js = \'document.body.scrollTop=10000\'
browser.execute_script(js)
time.sleep(3)
browser.save_screenshot(r\'phantomjs_photo\\xiala.png\')
#获取网页的代码,保存到文件中
html = browser.page_source
with open(r\'phantomjs_photo\\douban.html\',\'w\',encoding=\'utf8\') as fp:
fp.write(html)
browser.quit()
#自动搜索美女图片点开
from selenium import webdriver
import time
#驱动路径
path =r\'E:\\py\\爬虫day5\\geckodriver.exe\'
#模拟创建一个对象,然后通过对象去操作浏览器 注意方法Firefox() 大写F
browser = webdriver.Firefox(executable_path=path)
#print(browser)
#让他打开百度
url= "http://www.baidu.com"
browser.get(url)
#开启和操作需要加时间
time.sleep(3)
#找百度input搜索框
my_input = browser.find_element_by_id(\'kw\')
#往搜索框写文字
my_input.send_keys(\'美女\')
time.sleep(3)
#查找搜索按钮
button = browser.find_elements_by_class_name(\'s_btn\')[0]
button.click()
time.sleep(3)
#找到图片点击
image = browser.find_elements_by_class_name(\'op-img-address-link-imgs\')[2]
image.click()
time.sleep(2)
#关闭浏览器,退出浏览器
browser.quit()