python爬虫(gzip新浪微博为例)
发布日期:2021-06-29 12:30:13 浏览次数:3 分类:技术文章

本文共 523 字,大约阅读时间需要 1 分钟。

# coding=utf-8import urllib.requestimport gzipurl = 'http://news.sina.com.cn/'def getUrlContent(url):    # 返回页面内容    req = urllib.request.Request(url)    req.add_header("User-Agent",                   "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 QIHU 360SE")    data = urllib.request.urlopen(req).read()    # 解码    try:        html = gzip.decompress(data).decode("utf-8")    except:        html = data.decode("utf-8")    return htmlprint(getUrlContent(url))

转载地址:https://bupt-xbz.blog.csdn.net/article/details/78936702 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:计算机网络应用层笔记
下一篇:Linux运维笔记

发表评论

最新留言

逛到本站,mark一下
[***.202.152.39]2024年04月20日 07时34分29秒