美文网首页
python3抓取函数

python3抓取函数

作者: f09037cb27f7 | 来源:发表于2018-01-25 14:23 被阅读7次
#!/usr/bin/python3
from urllib import request
import ssl

# 支持https格式的URL传入
ssl._create_default_https_context = ssl._create_unverified_context

def get_html(url):
    headers = {
        'User-Agent': r'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
                    r'Chrome/45.0.2454.85 Safari/537.36 115Browser/6.0.3',
        'Connection': 'keep-alive'
    }
    req = request.Request(url, headers=headers)
    html = request.urlopen(req).read()
    return html

相关文章

网友评论

      本文标题:python3抓取函数

      本文链接:https://www.haomeiwen.com/subject/xpsvaxtx.html