淘宝商品页面的爬取.py(亲测有效)

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
    except:
        return "产生异常"

if __name__ == "__main__":
    url = "https://detail.tmall.com/item.htm?spm=a230r.1.14.22.2854442bmpEenU&id=602773281591&ns=1&abbucket=14" #所爬取商品的网址
    print(getHTMLText(url))

 

posted on 2020-12-29 22:05  打篮球的Curry  阅读(282)  评论(0编辑  收藏  举报