最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python第三方庫undetected_chromedriver的使用

 更新時(shí)間:2023年01月12日 10:02:45   作者:Docda  
這篇文章主要給大家介紹了關(guān)于Python第三方庫undetected_chromedriver的使用方法,文中通過實(shí)例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

undetected_chromedriver是專門針對(duì)瀏覽器識(shí)別做出來的拓展

直接使用undetected_chromedriver第三方庫

if __name__ == '__main__':

	from selenium import webdriver
	from selenium.webdriver.common.by import By
	from selenium.webdriver.support.ui import WebDriverWait
	from selenium.webdriver.support import expected_conditions
	import undetected_chromedriver.v2 as uc
	
	chrome_options = uc.ChromeOptions()
	chrome_options.add_argument("--disable-extensions")
	chrome_options.add_argument("--disable-popup-blocking")
	chrome_options.add_argument("--profile-directory=Default")
	chrome_options.add_argument("--ignore-certificate-errors")
	chrome_options.add_argument("--disable-plugins-discovery")
	chrome_options.add_argument("--incognito")
	chrome_options.add_argument('--no-first-run')
	chrome_options.add_argument('--no-service-autorun')
	chrome_options.add_argument('--no-default-browser-check')
	chrome_options.add_argument('--password-store=basic')
	chrome_options.add_argument('--no-sandbox')
	
	driver = uc.Chrome(options=chrome_options, executable_path='./driver/chromedriver')
	
	driver.delete_all_cookies()
	driver.get("https://accounts.google.com/signin/v2/identifier?service=accountsettings&continue=https%3A%2F%2Fmyaccount.google.com%3Futm_source%3Daccount-marketing-page%26utm_medium%3Dgo-to-account-button&flowName=GlifWebSignIn&flowEntry=ServiceLogin")
	
	driver.find_element_by_xpath('//input[@type="email"]').send_keys(email)
	input = WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="identifierNext"]')))
	input.click()
	
	WebDriverWait(driver, 10).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="password"]/div[1]/div/div[1]/input')))
	driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)
	
	input = WebDriverWait(driver, 100).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@id="passwordNext"]/div/button')))
	input.click()
	time.sleep(5)
	
	cookies = driver.get_cookies()
	cookies_arr = []
	for c in cookies:
	    if c['domain'].endswith('.google.com'):
	        cookies_arr.append(f'{c["name"]}={c["value"]}')
	
	driver.close()
	return "; ".join(cookies_arr)

使用seleniumwire的undetected_chromedriver拓展,好處是可以直接獲取到瀏覽器的請(qǐng)求記錄

from seleniumwire.undetected_chromedriver.v2 import Chrome, ChromeOptions
import time
if __name__ == '__main__':
    options = {}
    chrome_options = ChromeOptions()
    chrome_options.add_argument("--disable-gpu")
    chrome_options.add_argument("--incognito")
    chrome_options.add_argument("--disable-dev-shm-usage")
    # chrome_options.add_argument("--headless")
    chrome_options.add_argument(f"--proxy-server=http://192.168.100.24:60021")
    chrome_options.add_argument("--disable-popup-blocking")
    chrome_options.add_argument("--profile-directory=Default")
    chrome_options.add_argument("--ignore-certificate-errors")
    chrome_options.add_argument("--disable-plugins-discovery")
    chrome_options.add_argument('--no-first-run')
    chrome_options.add_argument('--no-service-autorun')
    chrome_options.add_argument('--no-default-browser-check')
    chrome_options.add_argument('--password-store=basic')
    chrome_options.add_argument('--no-sandbox')
    browser = Chrome(seleniumwire_options=options, options=chrome_options,executable_path='C:\Program Files\Google\Chrome\Application\chromedriver.exe',version_main=101)

    browser.get('https://portal.thecourierguy.co.za/track?ref=TCG107468416T')
    time.sleep(15)
    print(browser.page_source)
    for request in browser.requests:
        if request.response:
            print(request.path)
            if 'shipments' in request.path:
            	print(request.response.body)
            #獲取內(nèi)容為亂碼可嘗試用以下方法解碼
            #gzip.decompress(request.response.body).decode("utf-8")

其中version_main可以根據(jù)瀏覽器版本指定版本號(hào)

注意:

      使用seleniumwire.undetected_chromedriver有一個(gè)大坑

      輸入executable_path不會(huì)生效,因?yàn)樵趙ebdriver的源碼是單獨(dú)引用的undetected_chromedriver

所以不會(huì)接收到傳入的executable_path。

而在undetected_chromedriver源碼中,如果沒有傳入path就會(huì)每次啟動(dòng)去官網(wǎng)重新下載一個(gè)新的驅(qū)動(dòng)器,再編譯成可執(zhí)行的文存放在以下目錄

解決辦法:

      在webdriver的源碼中指定executable_path

這個(gè)帶有前綴id的chromedriver是有執(zhí)行權(quán)限的可執(zhí)行程序啦

(直接使用官網(wǎng)下載的可能會(huì)沒有權(quán)限,可以先直接運(yùn)行一次,去到對(duì)應(yīng)目錄下面找到一個(gè)就可以永久使用啦<其他的可以刪除>)

總結(jié)

到此這篇關(guān)于Python第三方庫undetected_chromedriver使用的文章就介紹到這了,更多相關(guān)Python undetected_chromedriver使用內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 利用python畫出AUC曲線的實(shí)例

    利用python畫出AUC曲線的實(shí)例

    今天小編就為大家分享一篇利用python畫出AUC曲線的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • 對(duì)python同一個(gè)文件夾里面不同.py文件的交叉引用方法詳解

    對(duì)python同一個(gè)文件夾里面不同.py文件的交叉引用方法詳解

    今天小編就為大家分享一篇對(duì)python同一個(gè)文件夾里面不同.py文件的交叉引用方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • Python如何限制輸入的數(shù)范圍

    Python如何限制輸入的數(shù)范圍

    在Python中,我們可以使用多種方法來限制用戶輸入的數(shù)值范圍,今天通過實(shí)例代碼給大家分享Python限制輸入的數(shù)范圍,感興趣的朋友一起看看吧
    2024-05-05
  • 使用Python和XML實(shí)現(xiàn)文件復(fù)制工具的完整代碼

    使用Python和XML實(shí)現(xiàn)文件復(fù)制工具的完整代碼

    在本篇博客中,我們將學(xué)習(xí)如何使用 wxPython 構(gòu)建一個(gè)簡單的文件復(fù)制工具,并將文件路徑和目標(biāo)目錄的配置信息保存到 XML 文件中,通過這種方式,我們可以在下次運(yùn)行程序時(shí)輕松加載之前保存的配置,需要的朋友可以參考下
    2024-08-08
  • python實(shí)現(xiàn)簡易連點(diǎn)器

    python實(shí)現(xiàn)簡易連點(diǎn)器

    本文主要介紹了python實(shí)現(xiàn)簡易連點(diǎn)器,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • Python機(jī)器學(xué)習(xí)入門(一)序章

    Python機(jī)器學(xué)習(xí)入門(一)序章

    這篇文章主要介紹了Python機(jī)器學(xué)習(xí)入門知識(shí),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • python腳本監(jiān)控logstash進(jìn)程并郵件告警實(shí)例

    python腳本監(jiān)控logstash進(jìn)程并郵件告警實(shí)例

    這篇文章主要介紹了python腳本監(jiān)控logstash進(jìn)程并郵件告警實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • Python測(cè)試框架:pytest學(xué)習(xí)筆記

    Python測(cè)試框架:pytest學(xué)習(xí)筆記

    這篇文章主要介紹了Python測(cè)試框架:pytest的相關(guān)資料,幫助大家更好的利用python進(jìn)行單元測(cè)試,感興趣的朋友可以了解下
    2020-10-10
  • 從基礎(chǔ)到進(jìn)階帶你玩轉(zhuǎn)Python中的JSON

    從基礎(chǔ)到進(jìn)階帶你玩轉(zhuǎn)Python中的JSON

    JSON是一種輕量級(jí)的數(shù)據(jù)交換格式,在Python中處理JSON數(shù)據(jù)是日常開發(fā)中的常見任務(wù)之一,本文將詳細(xì)介紹如何在Python中處理JSON對(duì)象,需要的可以參考下
    2024-12-12
  • Python網(wǎng)絡(luò)爬蟲之獲取網(wǎng)絡(luò)數(shù)據(jù)

    Python網(wǎng)絡(luò)爬蟲之獲取網(wǎng)絡(luò)數(shù)據(jù)

    本文介紹了Python中用于獲取網(wǎng)絡(luò)數(shù)據(jù)的重要工具之一——Requests庫,詳細(xì)講解了Requests庫的基本使用方法、請(qǐng)求方法、請(qǐng)求頭、請(qǐng)求參數(shù)、Cookies、Session等內(nèi)容,并結(jié)合實(shí)例代碼展示了Requests庫的應(yīng)用場(chǎng)景
    2023-04-04

最新評(píng)論

虎林市| 南郑县| 博罗县| 罗田县| 夏河县| 科技| 福建省| 汉川市| 长汀县| 南充市| 凤山县| 如皋市| 屯门区| 洛阳市| 凤城市| 西藏| 新晃| 闸北区| 扎兰屯市| 容城县| 迁安市| 华坪县| 吴川市| 宁德市| 云南省| 襄汾县| 来宾市| 温宿县| 壶关县| 德昌县| 吉隆县| 扎赉特旗| 武功县| 长治市| 延津县| 衡南县| 称多县| 松阳县| 天全县| 高雄县| 密山市|