A
A
Andrey382875122020-07-19 09:32:00
Python
Andrey38287512, 2020-07-19 09:32:00

I want to view network sites through python, how to do it?

5f13e884d8acf761631839.png
I want to receive network sites through python! What library is needed for this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2020-07-19
@Andrey38287512

I want to view network sites through python, how to do it?

Maybe all the same, the Network tab of the developer console and not "network sites"?
The code

Отсюда
import json
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.CHROME
caps['loggingPrefs'] = {'performance': 'ALL'}
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get('https://stackoverflow.com/questions/52633697/selenium-python-how-to-capture-network-traffics-response')

def process_browser_log_entry(entry):
    response = json.loads(entry['message'])['message']
    return response

browser_log = driver.get_log('performance') 
events = [process_browser_log_entry(entry) for entry in browser_log]
events = [event for event in events if 'Network.response' in event['method']]


Using selenium and browsermob-proxy:

from browsermobproxy import Server
from selenium import webdriver

server = Server("path/to/browsermob-proxy")
server.start()
proxy = server.create_proxy()

# Configure the browser proxy in chrome options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
browser = webdriver.Chrome(chrome_options = chrome_options)

#tag the har(network logs) with a name
proxy.new_har("google")

browser.get("http://www.google.co.in")
print(proxy.har) # returns a Network logs (HAR) as JSON 
server.stop()
browser.quit()

код отсюда

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question