京东商品页面爬取
选择了一款荣耀手机的页面(给华为打广告了,荣耀play真心不错)
import requests url = "https://item.jd.com/7479912.html" try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding print(r.text[:1000]) except: print("爬取失败")
这里给出更改发送信息的头部来模拟浏览器爬取网站信息
import requests url = "https://www.amazon.cn/gp/product/B01M8L5Z3Y" try: kv={'User-Agent':'Mozilla/5.0'} r = requests.get(url,headers=kv) r.raise_for_status() r.encoding = r.apparent_encoding print(r.text[1000:2000]) except: print("爬取失败")