编程语言
首页 > 编程语言> > python爬虫通用框架

python爬虫通用框架

作者:互联网

import requests


def getHTMLText(url):

try:

r = requests.get(url,timeout=30)

r.raise_for_status()  # 如果状态不是200,引发HTTP-Error异常

#print(r.status_code)

r.encoding = r.apparent_encoding

return r.text

except:

return "产生异常"


if __name__=="__main__":

url = "https://item.jd.com/5107323.html"

print(getHTMLText(url))


标签:__,status,框架,python,爬虫,url,getHTMLText,print,异常
来源: https://blog.51cto.com/13941177/2353820