edge selenium获取加载的url列表python3

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ 下载对应自己现在版本的driver

C:\Users\win\AppData\Local\Programs\Python\Python37\Scripts\pip.exe install msedge-selenium-tools selenium==3.141
#!/usr/bin/python
# -*- coding: utf-8 -*-

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from msedge.selenium_tools import Edge, EdgeOptions
import json
import time

driver_dir = r"D:\proj\pytest\msedgedriver.exe"
options = EdgeOptions()
options.use_chromium = True
options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"

# options.add_argument("--headless")
# options.add_argument('--no-sandbox')
# options.add_argument('--disable-dev-shm-usage')
# options.add_argument("disable-gpu")
options.add_experimental_option('w3c', False)
# options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36')
# options.add_argument('--proxy-server=http://192.168.180.10:1080')
# options.add_argument("-inprivate")

# for google chrome
d = DesiredCapabilities.CHROME
d['goog:loggingPrefs'] = {
    
    'browser': 'ALL'}
d['goog:loggingPrefs'] = {
    
    'performance': 'ALL'}

caps = {
    
    
    'loggingPrefs': {
    
    
        'performance': 'ALL',
    }
}

browser = Edge(executable_path=driver_dir, options=options, desired_capabilities=caps)
browser.get("https://www.baidu.com/")
# browser.save_screenshot('browser_size_screenshot.png')
# print(browser.log_types)  # 所有记录的日志类型
print("done")

url_list = []
all_perf_log = browser.get_log('performance')
for perf_one in all_perf_log:
    one_request_log = json.loads(perf_one.get('message'))
    try:
        if one_request_log['message']['method'] == 'Network.requestWillBeSent':
            request_url = one_request_log['message']['params']['request']['url']
            url_list.append(request_url)
    except Exception as e:
        pass

print(url_list)
print(len(url_list))

browser.quit()

猜你喜欢

转载自blog.csdn.net/c5113620/article/details/112399187
今日推荐