Python Selenium實(shí)現(xiàn)無可視化界面過程解析
無可視化界面的意義
有時候我們爬取網(wǎng)頁數(shù)據(jù),并不希望看其中的過程,只想看到最后的數(shù)據(jù)結(jié)果就可以了,這時候,***面就很有必要了!
代碼如下
from selenium import webdriverfrom time import sleep#實(shí)現(xiàn)無可視化界面from selenium.webdriver.chrome.options import Options#實(shí)現(xiàn)規(guī)避檢測from selenium.webdriver import ChromeOptions#實(shí)現(xiàn)無可視化界面的操作chrome_options = Options()chrome_options.add_argument(’--headless’)chrome_options.add_argument(’--disable-gpu’)#實(shí)現(xiàn)規(guī)避檢測option = ChromeOptions()option.add_experimental_option(’excludeSwitches’, [’enable-automation’])#如何實(shí)現(xiàn)讓selenium規(guī)避被檢測到的風(fēng)險bro = webdriver.Chrome(executable_path=’./chromedriver’,chrome_options=chrome_options,options=option)#無可視化界面(無頭瀏覽器) phantomJsbro.get(’https://www.baidu.com’)print(bro.page_source)sleep(2)bro.quit()
運(yùn)行效果:
打印出網(wǎng)頁代碼,證明爬取網(wǎng)站信息成功
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. asp批量添加修改刪除操作示例代碼2. ASP實(shí)現(xiàn)加法驗(yàn)證碼3. PHP循環(huán)與分支知識點(diǎn)梳理4. 讀大數(shù)據(jù)量的XML文件的讀取問題5. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案6. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)7. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能8. 解析原生JS getComputedStyle9. jsp+servlet實(shí)現(xiàn)猜數(shù)字游戲10. css代碼優(yōu)化的12個技巧
