selenium Network獲取


調用工具:Browsermob-Proxy

 

Browsermob-Proxy是一個開源的Java編寫的基於LittleProxy的代理服務。Browsermob-Proxy的具體流程有點類似與Flidder或Charles。即開啟一個端口並作為一個標准代理存在,當HTTP客戶端(瀏覽器等)設置了這個代理,則可以抓取所有的請求細節並獲取返回內容。

 

1、下載zip包,https://github.com/lightbody/browsermob-proxy/releases ,支持Linux和Windows。

2、pip install browsermob-proxy

3、代碼

from browsermobproxy import Server
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#啟動

server = Server(r'.\browsermob-proxy-2.1.4\bin\browsermob-proxy.bat')

server.start()
proxy = server.create_proxy()

#設置driver options

chrome_options = Options()
chrome_options.add_argument('--proxy-server={0}'.format(proxy.proxy))

driver = webdriver.Chrome(chrome_options=chrome_options)

#

url = 'http://st.gdjnpx.cn/'
proxy.new_har('zhiye', options={'captureHeaders': True, 'captureContent': True})
driver.get(url)

 

res = proxy.har
for entry in res['log']['entries']:
  res_url = entry['request']['url']
  if "/ApiUser/login?useraccount" in res_url:
    res_response = entry['response']
    print(res_response)
server.stop()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM