1 """实例1:京东商品页面的爬取""" 2 3 4 import requests 5 6 url = "https://item.jd.com/100012545852.html" 7 try: 8 # 更改头部信息 9 kv = {'user-agent': 'Mozilla/5.0'} 10 r = requests.get(url, headers=kv) 11 r.raise_for_status() 12 r.encoding = r.apparent_encoding 13 # print(r.request.headers) 14 print(r.text[:1000]) 15 except: 16 print("爬取失败")