import urllib.request
def get_site_html(url):
source = urllib.request.urlopen(url).read()
return source
我正在尝试创建此函数,但它向我抛出了以下error--
HTTPError: HTTP Error 404: Not Found
请帮助我。
答案 0 :(得分:1)
import urllib.request
req = urllib.request.Request('your link here')
with urllib.request.urlopen(req) as response:
the_page = response.read()
答案 1 :(得分:1)
import urllib.request
requ = urllib.request.Request(url='')
with urllib.request.urlopen(requ) as f:
data = f.read()
尝试此操作,否则您可能需要.decode语句以及.read