'''
Python 3.7
selenium==3.141.0
urllib3==1.26.2
Chromium 109.0.5405.0 (32 位)
'''
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
options = webdriver.ChromeOptions()
chrome_location = r'D:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe'
chromedriver_path = r'D:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver_win32\\chromedriver.exe'
options.binary_location = chrome_location
'goog:loggingPrefs': {'performance': 'ALL'},
'goog:chromeOptions': {'extensions': [], 'args': ['--headless']}
'goog:loggingPrefs': {'performance': 'ALL'}
driver = webdriver.Chrome(executable_path=chromedriver_path, options=options, desired_capabilities=caps)
list_query = ['135.89.67.33', '34.66.45.22']
driver.get(f'http://ip-api.com/json/{query}')
logs = driver.get_log("performance")
log = json.loads(item["message"])["message"]
if log["method"] == 'Network.responseReceived':
url = log['params']['response']['url']
request_id = log['params']['requestId']
response_headers = log['params']['response']['headers']
status_code = log['params']['response']['status']
request_data = driver.execute_cdp_cmd('Network.getRequestPostData', {'requestId': request_id})
except WebDriverException:
response_body = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': request_id})['body']
print('响应', response_body)
请求 http://ip-api.com/json/135.89.67.33
响应 {"status":"success","country":"United States","countryCode":"US","region":"IN","regionName":"Indiana","city":"Indianapolis","zip":"46204","lat":39.7709,"lon":-86.1585,"timezone":"America/Indiana/Indianapolis","isp":"AT\u0026T Services","org":"AT\u0026T Services, Inc.","as":"","query":"135.89.67.33"}
请求 http://ip-api.com/json/34.66.45.22
响应 {"status":"success","country":"United States","countryCode":"US","region":"IA","regionName":"Iowa","city":"Council Bluffs","zip":"","lat":41.2619,"lon":-95.8608,"timezone":"America/Chicago","isp":"Google LLC","org":"Google Cloud (us-central1)","as":"AS396982 Google LLC","query":"34.66.45.22"}
'''
Python 3.8
selenium==4.21.0
urllib3==2.2.2
Chromium 109.0.5405.0 (32 位)
'''
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException
chrome_location = r'D:\\Program Files (x86)\\Google\Chrome\\Application\\chrome.exe'
chromedriver_path = r'D:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver_win32\\chromedriver.exe'
options.set_capability("goog:loggingPrefs", {"performance": "ALL", "browser": "ALL"})
options.binary_location = chrome_location
service = Service(executable_path=chromedriver_path)
driver = webdriver.Chrome(service=service, options=options)
list_query = ['135.89.67.33', '34.66.45.22']
driver.get(f'http://ip-api.com/json/{query}')
logs = driver.get_log("performance")
log = json.loads(item["message"])["message"]
if log["method"] == 'Network.responseReceived':
url = log['params']['response']['url']
request_id = log['params']['requestId']
response_headers = log['params']['response']['headers']
status_code = log['params']['response']['status']
request_data = driver.execute_cdp_cmd('Network.getRequestPostData', {'requestId': request_id})
except WebDriverException:
response_body = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': request_id})['body']
print('响应', response_body)
'''
参考:
https://blog.csdn.net/MXB_1220/article/details/131775148
https://blog.csdn.net/u014376732/article/details/133973141
https://www.cnblogs.com/szyicol/p/18093390
https://www.cnblogs.com/superhin/p/15023302.html
https://segmentfault.com/q/1010000043296964
'''