标签:return www enc htm ret 编码 _for status requests
import requests def getHTMLText(url): try: r = requests.get(url, timeput=30) r.raise_for_status() #如果状态不是200,引发异常 r.encoding = ‘utf-8‘ #无论原来用什么编码,都改成utf-8 return r.text except: return "" url = "http://www.baidu.com" print(getHTMLText(url))
标签:return www enc htm ret 编码 _for status requests
原文地址:https://www.cnblogs.com/lulingboke/p/12875529.html