python网络爬虫请求头

import requests requestHead = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"} response = requests.get('https://www.bilibili.com/',headers = requestHead) if response.ok: print(response.text) with open('./bil.html', 'w', encoding='utf-8') as f: f.write(response.text) else: print('请求失败')
来源https://blog.csdn.net/qq_69183322/article/details/140425186
关键在User-Agent,使用Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36也可以得到页面

posted @ 2025-06-03 23:08  0-jianghe-0  阅读(25)  评论(0)    收藏  举报