欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python第三方庫(kù)undetected_chromedriver的使用

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

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

直接使用undetected_chromedriver第三方庫(kù)

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

解決辦法:

      在webdriver的源碼中指定executable_path

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

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

總結(jié)

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

相關(guān)文章

  • 關(guān)于pip install uwsgi安裝失敗問(wèn)題的解決方案

    關(guān)于pip install uwsgi安裝失敗問(wèn)題的解決方案

    這篇文章主要介紹了關(guān)于pip install uwsgi安裝失敗問(wèn)題的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Jupyter Notebook如何導(dǎo)入python文件時(shí)的問(wèn)題

    Jupyter Notebook如何導(dǎo)入python文件時(shí)的問(wèn)題

    這篇文章主要介紹了Jupyter Notebook如何導(dǎo)入python文件時(shí)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Python使用指定端口進(jìn)行http請(qǐng)求的例子

    Python使用指定端口進(jìn)行http請(qǐng)求的例子

    今天小編就為大家分享一篇Python使用指定端口進(jìn)行http請(qǐng)求的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • Python3.10和Python3.9版本之間的差異介紹

    Python3.10和Python3.9版本之間的差異介紹

    大家好,本篇文章主要講的是Python3.10和Python3.9版本之間的差異介紹,感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下哦
    2021-12-12
  • Django中ORM基本應(yīng)用與原理解析

    Django中ORM基本應(yīng)用與原理解析

    Django的ORM模塊是框架特色功能之一,它把數(shù)據(jù)表與Python類對(duì)應(yīng)、表字段與類屬性對(duì)應(yīng)、類實(shí)例與數(shù)據(jù)記錄對(duì)應(yīng),并將對(duì)類實(shí)例的操作映射到數(shù)據(jù)庫(kù)中,這篇文章主要介紹了Django?ORM基本應(yīng)用與原理剖析,需要的朋友可以參考下
    2022-10-10
  • 用Python監(jiān)控NASA TV直播畫面的實(shí)現(xiàn)步驟

    用Python監(jiān)控NASA TV直播畫面的實(shí)現(xiàn)步驟

    本文分享一個(gè)名為"Spacestills"的開源程序,它可以用于查看 NASA TV 的直播畫面(靜止幀)
    2021-05-05
  • python中正則表達(dá)式findall的用法實(shí)例

    python中正則表達(dá)式findall的用法實(shí)例

    在寫著自動(dòng)化測(cè)試的腳本時(shí)重新復(fù)習(xí)了一下正則表達(dá)式findall()方法,下面這篇文章主要給大家介紹了關(guān)于python中正則表達(dá)式findall用法的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • tf.truncated_normal與tf.random_normal的詳細(xì)用法

    tf.truncated_normal與tf.random_normal的詳細(xì)用法

    本篇文章主要介紹了tf.truncated_normal與tf.random_normal的詳細(xì)用法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-03-03
  • 通過(guò)OpenCV實(shí)現(xiàn)對(duì)指定顏色的物體追蹤

    通過(guò)OpenCV實(shí)現(xiàn)對(duì)指定顏色的物體追蹤

    這篇文章主要介紹的是通過(guò)OpenCV實(shí)現(xiàn)對(duì)特定顏色的物體追蹤,文中實(shí)驗(yàn)用的是綠蘿的樹葉。本文的示例代碼講解詳細(xì),對(duì)學(xué)習(xí)OPenCV有一定的幫助,感興趣的小伙伴可以了解一下
    2021-12-12
  • python串口讀取數(shù)據(jù)的實(shí)例

    python串口讀取數(shù)據(jù)的實(shí)例

    這篇文章主要介紹了python串口讀取數(shù)據(jù)的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09

最新評(píng)論