爬蟲——phantomJs

PhantomJS是一款無界面的瀏覽器,
驅動下載:
http://phantomjs.org/download.html
流程與selenium一致,只是改了webdriver 的瀏覽器類型和驅動目錄,增加了截屏功能bro.save_screenshot('./1.png')

from selenium import webdriver as wd

bro = wd.PhantomJS(executable_path='./phantomjs-2.1.1-windows/bin/phantomjs')
bro.get('https://www.baidu.com')

# 截屏的操作 
bro.save_screenshot('./1.png')
text = bro.find_element_by_id('kw')
text.send_keys('人名幣') 

# 找到動作按鈕
button = bro.find_element_by_id('su')

# 點擊操作
button.click()

# 截屏的操作 
bro.save_screenshot('./2.png')

bro.quit()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章