import requests
r =requests.get("http://html.//www.baidu.com")
def gethtmltext():
try:
r = requests.get(url, timeout =30)
r.raise_for_status()
r.encoding = 'utf-8'
return r.text
except:
return""
url = 'http://html.//www.baidu.com'
print (gethtmltext(url))
报错:
TypeError: gethtmltext() takes 0 positional arguments but 1 was given
gethtmltext()函数没有参数,但是在使用时给了一个参数
在gethtmltext中增添一个参数即可
即def gethtmltext(url):