|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
def 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=")
复制代码
|
|