from playwright.sync_api import sync_playwright r''' 可以利用playwright框架抓浏览器网络请求包,抓响应包输出会有识别不了的字符编码报错(暂无解决,或者不用解决)。 ''' # 回调函数获取请求url、请求头、请求体 def on_request(request): print(f'Request URL: {request.url}') print(f'Request Headers: {request.headers}') if request.post_data is not None: print(f'Request Body: {request.post_data.decode()}') with sync_playwright() as p: browser = p.chromium.launch() page = browser.new_page() # 设置请求监听器 page.on('request', on_request) page.goto('https://www.baidu.com') browser.close()
标签:playwright,33,Request,request,sync,print,page,抓包 From: https://www.cnblogs.com/chenzhi2023/p/17860684.html