Python爬虫selenium、PhanmJs
生活随笔
收集整理的這篇文章主要介紹了
Python爬虫selenium、PhanmJs
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
selenium:可以模擬鼠標進行一些操作
實例1:實現自動打開google瀏覽器,進行百度搜索,并關閉瀏覽器
from selenium import webdriver from time import sleep#指定安裝google瀏覽器驅動程序 bro = webdriver.Chrome(r'E:\Spider爬蟲視頻\day03\chromedriver_win32\chromedriver.exe')#打開瀏覽器發起請求 bro.get('https://www.baidu.com')sleep(2)#定位到搜索框 my_text = bro.find_element_by_id('kw') #向搜索框中輸入一個關鍵字 my_text.send_keys('西紅柿首富')sleep(5)#定位到搜索按鈕 my_button = bro.find_element_by_id('su') my_button.click()sleep(6) #關閉瀏覽器 bro.quit()
?
PhanmJs:無界面瀏覽器
?
from selenium import webdriver from time import sleep#指定phantomjs驅動 bro = webdriver.PhantomJS(r'E:\Spider爬蟲視頻\day03\phantomjs-2.1.1-windows\bin\phantomjs.exe')#打開瀏覽器發起請求 bro.get('https://www.baidu.com') bro.save_screenshot('./首頁.png')#用來截屏 sleep(2)#定位到搜索框 my_text = bro.find_element_by_id('kw') #向搜索框中輸入一個關鍵字 my_text.send_keys('人民幣') bro.save_screenshot('./2.png') sleep(2)#定位到搜索按鈕 my_button = bro.find_element_by_id('su') my_button.click()sleep(5) bro.save_screenshot('./3.png') #關閉瀏覽器 bro.quit()?
轉載于:https://www.cnblogs.com/yangzhizong/p/9714387.html
總結
以上是生活随笔為你收集整理的Python爬虫selenium、PhanmJs的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面试题16: 数值的整数次方
- 下一篇: redis-初识