import requests
def jingdong(url):
try:
r= requests.get(url,timeout=10)
print(r.status_code)
r.raise_for_status()
r.encoding = r.apparent_encoding
str1 = r.text.replace('\ufffd','')
return str1
return r.text
except:
return "error"
if __name__ =="__main__":
url= "https://item.jd.com/31042415497.html"
print(jingdong(url))
encode 编码
decode 解码
爬虫要搞清楚 你爬的内容是什么编码,进而再去进行操作
推荐阅读python encode decode 函数