import requests
def getHTMLText(url):
try:
r = requests.get(url, timeout=30)
r.raise_for_status() # 如果不是200,引发HTTPError异常
r.encoding = r.apparent_encoding
return r.text[:1000]
except:
return "产生异常"
if __name__ == "__main__":
url="https://item.jd.com/100008348542.html"
print(getHTMLText(url))
Python爬取京东商品
猜你喜欢
转载自blog.csdn.net/KK_2018/article/details/104096723
今日推荐
周排行