爬取豆瓣时获取数据出了问题
import urllib.requestdef main():
askurl("https://movie.douban.com/top250?start=")
def askurl(url):
head = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}
req = urllib.request.Request(url,headers=head)
html = ''
response = urllib.request.urlopen(req)
html= response.read().decode('utf-8')
print(html)
求大佬,为什么我这个什么都打印不出来?详情参见图片。 本帖最后由 suchocolate 于 2021-3-31 10:25 编辑
只定义了函数,没用调用运行函数。import urllib.request
def askurl(url):
head = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}
req = urllib.request.Request(url, headers=head)
response = urllib.request.urlopen(req)
html = response.read().decode('utf-8')
print(html)
if __name__ == '__main__':
askurl("https://movie.douban.com/top250?start=")
页:
[1]