linkais 发表于 2020-10-27 22:46:34

help!


import urllib.request


def copy_artical(url):
    req = urllib.request.Request(url)
    req.add_header('User-Agent','Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko')
    html = urllib.request.urlopen(req).read().decode('GB2312')
    return html
url = str(input('请输入你要爬取网站的网址:'))
a = copy_artical(url)
with open('copy_in','w') as f:
    f.write(a)

为啥我写的这个出来的总是一个不能打开不能压缩的文件?

kogawananari 发表于 2020-10-27 22:56:36

没写后缀 至少改成 'copy_in.txt'
页: [1]
查看完整版本: help!