Python Selenium實(shí)現(xiàn)無可視化界面過程解析
無可視化界面的意義
有時(shí)候我們爬取網(wǎng)頁數(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ī)避檢測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)險(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)頁代碼,證明爬取網(wǎng)站信息成功
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP新手必備的基礎(chǔ)知識(shí)2. asp文件用什么軟件編輯3. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )4. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對象5. JAVA 實(shí)現(xiàn)延遲隊(duì)列的方法6. JS中6個(gè)對象數(shù)組去重的方法7. vue+element開發(fā)一個(gè)谷歌插件的全過程8. Vue axios獲取token臨時(shí)令牌封裝案例9. 通過IEAD+Maven快速搭建SSM項(xiàng)目的過程(Spring + Spring MVC + Mybatis)10. 利用CSS制作3D動(dòng)畫

網(wǎng)公網(wǎng)安備