屏蔽網(wǎng)站對selenium的檢測

使用mitmproy可以屏蔽對selenium的檢測

在爬取淘寶拉取驗證碼的時候,可以使用mitmproxy中的flow.response對數(shù)據(jù)響應(yīng)進行更改

import re  
from mitmproxy import ctx  
    
def response(flow):  
  """修改應(yīng)答數(shù)據(jù) 
  """  
  if '/js/yoda.' in flow.request.url:  
      # 屏蔽selenium檢測 
      for webdriver_key in ['webdriver', '__driver_evaluate', '__webdriver_evaluate', '__selenium_evaluate', '__fxdriver_evaluate', '__driver_unwrapped', '__webdriver_unwrapped', '__selenium_unwrapped', '__fxdriver_unwrapped', '_Selenium_IDE_Recorder', '_selenium', 'calledSelenium', '_WEBDRIVER_ELEM_CACHE', 'ChromeDriverw', 'driver-evaluate', 'webdriver-evaluate', 'selenium-evaluate', 'webdriverCommand', 'webdriver-evaluate-response', '__webdriverFunc', '__webdriver_script_fn', '__$webdriverAsyncExecutor', '__lastWatirAlert', '__lastWatirConfirm', '__lastWatirPrompt', '$chrome_asyncScriptInfo', '$cdc_asdjflasutopfhvcZLmcfl_']:  
          ctx.log.info('Remove "{}" from {}.'.format(webdriver_key, flow.request.url))  
          flow.response.text = flow.response.text.replace('"{}"'.format(webdriver_key), '"NO-SUCH-ATTR"')  
      flow.response.text = flow.response.text.replace('t.webdriver', 'false')  
      flow.response.text = flow.response.text.replace('ChromeDriver', '') 
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容