Python Selenium實(shí)現(xiàn)無可視化界面過程解析
無可視化界面的意義
有時(shí)候我們爬取網(wǎng)頁(yè)數(shù)據(jù),并不希望看其中的過程,只想看到最后的數(shù)據(jù)結(jié)果就可以了,這時(shí)候,***面就很有必要了!
代碼如下
from selenium import webdriverfrom time import sleep#實(shí)現(xiàn)無可視化界面from selenium.webdriver.chrome.options import Options#實(shí)現(xiàn)規(guī)避檢測(cè)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ī)避檢測(cè)option = ChromeOptions()option.add_experimental_option(’excludeSwitches’, [’enable-automation’])#如何實(shí)現(xiàn)讓selenium規(guī)避被檢測(cè)到的風(fēng)險(xiǎn)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)頁(yè)代碼,證明爬取網(wǎng)站信息成功
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. chat.asp聊天程序的編寫方法2. JSP之表單提交get和post的區(qū)別詳解及實(shí)例3. jsp cookie+session實(shí)現(xiàn)簡(jiǎn)易自動(dòng)登錄4. PHP循環(huán)與分支知識(shí)點(diǎn)梳理5. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法6. JSP+Servlet實(shí)現(xiàn)文件上傳到服務(wù)器功能7. jsp實(shí)現(xiàn)textarea中的文字保存換行空格存到數(shù)據(jù)庫(kù)的方法8. ASP中格式化時(shí)間短日期補(bǔ)0變兩位長(zhǎng)日期的方法9. JavaWeb Servlet中url-pattern的使用10. jsp EL表達(dá)式詳解
