国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求 隱藏chrome

這篇具有很好參考價值的文章主要介紹了python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求 隱藏chrome。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

安裝chromedriver

下載

chromedriver的版本一定要與Chrome的版本一致,不然就不起作用。

有兩個下載地址:

1、http://chromedriver.storage.googleapis.com/index.html

2、CNPM Binaries Mirror

當(dāng)然,你首先需要查看你的Chrome版本,在瀏覽器中輸入chrome://version/

python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求
隱藏chrome

?放chromedriver在chrome安裝目錄

python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求
隱藏chrome

?默認(rèn)目錄一般為:C:\Program Files\Google\Chrome\Application

獲取網(wǎng)頁源碼

from selenium import webdriver
from selenium.webdriver.common.by import By
browser = webdriver.Chrome()
browser.get(a[0])#填url
time.sleep(3)
b=browser.page_source
print(b)

常用配置參數(shù):

# 添加UA
options.add_argument('user-agent="MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"')
 
# 指定瀏覽器分辨率
options.add_argument('window-size=1920x3000')
 
# 谷歌文檔提到需要加上這個屬性來規(guī)避bug
chrome_options.add_argument('--disable-gpu')
 
 # 隱藏滾動條, 應(yīng)對一些特殊頁面
options.add_argument('--hide-scrollbars')
 
# 不加載圖片, 提升速度
options.add_argument('blink-settings=imagesEnabled=false')
 
# 瀏覽器不提供可視化頁面. linux下如果系統(tǒng)不支持可視化不加這條會啟動失敗
options.add_argument('--headless')
 
# 以最高權(quán)限運行
options.add_argument('--no-sandbox')
 
# 手動指定使用的瀏覽器位置
options.binary_location = r"C:Program Files (x86)GoogleChromeApplicationchrome.exe"
 
#添加crx插件
option.add_extension('d:crxAdBlock_v2.17.crx')
 
# 禁用JavaScript
option.add_argument("--disable-javascript")
 
# 設(shè)置開發(fā)者模式啟動,該模式下webdriver屬性為正常值
options.add_experimental_option('excludeSwitches', ['enable-automation'])
 
# 禁用瀏覽器彈窗
prefs = { 
    'profile.default_content_setting_values' :  { 
        'notifications' : 2 
     } 
} 
options.add_experimental_option('prefs',prefs)
 
# 添加代理 ip
options.add_argument("--proxy-server=http://XXXXX.com:80")
 
driver = webdriver.Chrome(chrome_options=chrome_options)

XPATH獲取元素

    content=browser.find_element(value='//*[@id="img-content"]',by=By.XPATH)
    print(content.text)

隱藏chrome

chrome_opts = webdriver.ChromeOptions()
chrome_opts.add_argument("--headless")
browser = webdriver.Chrome(options=chrome_opts)

最小化瀏覽器窗口

browser = webdriver.Chrome(options=chrome_opts)
browser.minimize_window()

點擊元素 寫入元素 生成隨機字符串

ming=''.join(random.choice(string.ascii_letters+ string.digits) for _ in range(12))
print(ming)
browser.find_element(value='//*[@id="name"]', by=By.XPATH).send_keys(ming)
browser.find_element(value='//*[@id="email"]', by=By.XPATH).send_keys(ming+'@qq.com')

browser.find_element(value='//*[@id="imtype"]', by=By.XPATH).click()
time.sleep(1)
browser.find_element(value='/html/body/div[1]/div/section/div/div[6]/div/div/ul/li[2]/a', by=By.XPATH).click()

點擊第一個谷歌搜索結(jié)果

browser.find_element(value='//*[@id="rso"]/div[1]/div/div[1]/div/div/div[1]/div/a/h3', by=By.XPATH).click()

Python往文件追加內(nèi)容

f = open('test.txt', 'a')
f.write('Hello Everyone\n')
f.close()

Selenium設(shè)置頁面超時時間-快速終止頁面加載

當(dāng)使用Selenium爬取一些頁面時,有些頁面加載速度特別慢,而我們又不需要等待頁面完全加載完畢。
此時可以通過driver.set_page_load_timeout()來設(shè)置頁面超時時間。
捕獲異常,并執(zhí)行js腳本window.stop()即可實現(xiàn),代碼如下。

from selenium import webdriver

driver = webdriver.Chrome()
driver.set_page_load_timeout(3)

try:
    driver.get('https://hk.louisvuitton.com/zht-hk/homepage')
    print('finish load ....')
except Exception:
    driver.execute_script('window.stop()')
    print(driver.title)
finally:
    driver.quit()

pj網(wǎng)頁防止開發(fā)者模式

使用 CDP(Chrome Devtools-Protocol),您可以在 JS 文件(檢測器)加載框架之前運行代碼。因此,使用這些代碼刪除“webdriver True”屬性:

Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })

關(guān)鍵代碼:

from selenium.webdriver import Chrome
driver = Chrome('D://chromedriver.exe')
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => undefined
    })
  """
})
driver.get('http://pythonlearner.com')

但是,如果您現(xiàn)在將 Chrome 升級到 88。上面提到的方法將毫無用處。幸運的是,我們?nèi)匀挥幸粋€解決方案(添加此代碼)

chrome_options.add_argument("--disable-blink-features=AutomationControlled")

截取數(shù)據(jù)請求

from seleniumwire import webdriver

browser = webdriver.Chrome("chromedriver.exe")
browser.request_interceptor = interceptor_request
browser.response_interceptor = interceptor_response
browser.get("http://localhost:8088/inner/t4")

for request in browser.requests:
    print(request.url)
    print(request.response.body)

Selenium-處理滑塊驗證碼-openCV識別

opencv基礎(chǔ)操作

#opencv基礎(chǔ)操作
import cv2
#圖像的基本操作
#圖像的讀取
#img cv2.imread(''")
#查看對應(yīng)的像素
#img[120,120]
img[120,120]=[255,255,0]
#修改圖像尺寸
resized=cv2.resize(img,(960,540))
#修改窗口尺寸
cv2.namedWindow("img",0)
cv2.resizeWindow("img",640,480)
#圖像展示
#cv2.imshow('img',img)
#圖像寫入
cv2.imwrite('',img)
cv2.imencode('.jpg',img)[1].tofile('')
#等待用戶按下任意鍵的時間
cv2.waitKey()#括號里的是時間,單位是ms
#銷毀窗口
cv2.destroyAlLWindows()#銷毀當(dāng)前所有正在顯示的窗口
#1、隱藏Chrome 正受到自動測試軟件的控制
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
browser = webdriver.Chrome(options=chrome_options)

F12進入調(diào)試界面總是停留在Paused in debugger解決辦法

有時候我們在某個界面點擊F12后,頁面會出現(xiàn)下面這樣的按鈕,導(dǎo)致無法對界面進行實時操作:
python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求
隱藏chrome
我使用的是edge瀏覽器,解決辦法如下:
python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求
隱藏chrome
點擊上面的禁止按鈕,再點擊一下頁面上下面的按鈕就可以了!
python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求
隱藏chrome

Playwright 為現(xiàn)代 web 應(yīng)用提供了跨瀏覽器、快速且可靠的端到端的測試能力。 | Playwright 中文文檔 | Playwright 中文網(wǎng)

參考:selenium 安裝與 chromedriver安裝 - Rogn - 博客園 (cnblogs.com)

python 用seleniumwire模塊獲取網(wǎng)站登陸后的請求頭token字符串?dāng)?shù)據(jù)_井底 之魚的博客-CSDN博客

【淺記】使用seleniumwire滑動極兔滑塊_seleniumwire拖動滑動_Docda的博客-CSDN博客

https://www.cnblogs.com/qlqwjy/p/16519286.html

python selenium 保存網(wǎng)頁緩存,保持登錄?https://www.cnblogs.com/royfans/p/16714805.html

?文章來源地址http://www.zghlxwxcb.cn/news/detail-425109.html

到了這里,關(guān)于python selenium playwright庫使用教程 破解網(wǎng)頁防止開發(fā)者模式 截取數(shù)據(jù)請求 隱藏chrome的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • Python爬蟲基礎(chǔ)(三):使用Selenium動態(tài)加載網(wǎng)頁

    Python爬蟲基礎(chǔ)(三):使用Selenium動態(tài)加載網(wǎng)頁

    Python爬蟲基礎(chǔ)(一):urllib庫的使用詳解 Python爬蟲基礎(chǔ)(二):使用xpath與jsonpath解析爬取的數(shù)據(jù) Python爬蟲基礎(chǔ)(三):使用Selenium動態(tài)加載網(wǎng)頁 Python爬蟲基礎(chǔ)(四):使用更方便的requests庫 Python爬蟲基礎(chǔ)(五):使用scrapy框架 (1)Selenium是一個用于Web應(yīng)用程序測試的工具。

    2024年02月06日
    瀏覽(30)
  • Python Selenium網(wǎng)頁自動化利器使用詳解

    Python Selenium網(wǎng)頁自動化利器使用詳解

    Selenium是一個自動化測試工具,主要用于模擬用戶在Web應(yīng)用程序中的交互操作。雖然它最初被設(shè)計用于自動化測試,但也被廣泛用于網(wǎng)頁數(shù)據(jù)抓取、網(wǎng)頁自動化操作和網(wǎng)頁測試。 首先,需要安裝Selenium庫。使用pip來安裝Selenium: 1 pip install selenium 此外,需要下載并安裝一個瀏覽

    2024年01月18日
    瀏覽(100)
  • Python網(wǎng)頁抓取- python selenium使用方法和代碼示例

    Selenium可以模擬網(wǎng)頁操作,抓取頁面內(nèi)容,主要通過webdriver模塊實現(xiàn),為了方便理解,按照實例的操作步驟逐一介紹(函數(shù)參數(shù)不具體展開,參考下面代碼實例即可理解): 獲取browser實例 通過webdriver.Chorme(), webdriver.Edge(), webdriver.Firefox(), 來獲取browser實例: browser = webdriver.C

    2024年01月23日
    瀏覽(48)
  • Python爬蟲——Selenium在獲取網(wǎng)頁數(shù)據(jù)方面的使用

    Python爬蟲——Selenium在獲取網(wǎng)頁數(shù)據(jù)方面的使用

    目錄 一、Selenium (一)引入 ?(二)啟動瀏覽器 二、操作 (一)點擊 (二)輸入 三、數(shù)據(jù)獲取 四、特點 五、抓取拉鉤實例 六、其他操作 (一)窗口切換 代碼 (二)操作下拉列表/無頭瀏覽器 代碼 ????????一個電影票房的網(wǎng)站里,響應(yīng)數(shù)據(jù)是一串完全看不懂的字符串

    2024年02月07日
    瀏覽(24)
  • Python使用Selenium Webdriver爬取網(wǎng)頁所有內(nèi)容

    Python使用Selenium Webdriver爬取網(wǎng)頁所有內(nèi)容

    有時候,我們在用urllib或者requests庫抓取頁面時,得到的html源代碼和瀏覽器中看到的不一樣。這將是我們面臨的一個非常常見的問題?,F(xiàn)在網(wǎng)頁越來越多地采用Ajax、前端模塊化工具來構(gòu)建,整個網(wǎng)頁可能都是由JavaScript渲染出來的,也就是說原始的HTML代碼可能就是一個空殼,

    2023年04月08日
    瀏覽(30)
  • Python爬蟲|使用Selenium輕松爬取網(wǎng)頁數(shù)據(jù)

    Python爬蟲|使用Selenium輕松爬取網(wǎng)頁數(shù)據(jù)

    1. 什么是selenium? Selenium是一個用于Web應(yīng)用程序自動化測試工具。Selenium測試直接運行在瀏覽器中,就像真正的用戶在操作瀏覽器一樣。支持的瀏覽器包括IE,F(xiàn)irefox,Safari,Chrome等。 Selenium可以驅(qū)動瀏覽器自動執(zhí)行自定義好的邏輯代碼,也就是可以通過代碼完全模擬成人類使用

    2024年02月04日
    瀏覽(32)
  • Selenium教程__使用switch_to.frame處理網(wǎng)頁框架切換(13)

    Selenium教程__使用switch_to.frame處理網(wǎng)頁框架切換(13)

    與在新窗口打開一個網(wǎng)頁后需要切換窗口才能定位元素一樣,在iframe標(biāo)簽中的元素也不能直接定位,需要切換到對應(yīng)的iframe框架中才能進行元素定位。 完成網(wǎng)頁框架切換操作需要用selenium中的兩個方法 driver.switch_to.frame(frame_reference):切換到網(wǎng)頁框架內(nèi),frame_reference為框架元素

    2024年02月06日
    瀏覽(15)
  • Python使用selenium自動打開網(wǎng)頁、輸入賬號密碼并登錄

    此處示例使用 谷歌Chrome瀏覽器 ,打開指定網(wǎng)頁,輸入賬號密碼,并登錄; 代碼思路如下: ① 加載Chrome瀏覽器 驅(qū)動程序 (下載地址) ? ? ? ? 具體下載方式可以參考:使用selenium自動打開谷歌瀏覽器 ② 打開url 鏈接(此處建議sleep等待一下,避免網(wǎng)速或內(nèi)存不良時,導(dǎo)致網(wǎng)

    2024年02月11日
    瀏覽(25)
  • 華納云:Python中如何使用Selenium爬取網(wǎng)頁數(shù)據(jù)

    這篇文章主要介紹“Python中如何使用Selenium爬取網(wǎng)頁數(shù)據(jù)”,在日常操作中,相信很多人在Python中如何使用Selenium爬取網(wǎng)頁數(shù)據(jù)問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Python中如何使用Selenium爬取網(wǎng)頁數(shù)據(jù)”的疑惑有所幫助!接下

    2024年02月07日
    瀏覽(26)
  • 嗨,各位Python程序員,放棄selenium,試試年輕的Playwright如何?

    嗨,各位Python程序員,放棄selenium,試試年輕的Playwright如何?

    上一篇博客我們首次接觸年輕的自動化模塊 playwright ,驚訝于其代碼錄制功能,今天咱們接著學(xué)習(xí)一下,其 API 相關(guān)知識。 正式學(xué)習(xí)前,先把基礎(chǔ)示例代碼呈現(xiàn)給大家。 注意上述代碼使用的不是 無頭瀏覽器 ,運行代碼得到請求站點的標(biāo)題,下面繼續(xù)對代碼進行擴展。 通過瀏

    2023年04月09日
    瀏覽(24)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包