美文网首页python爬虫
一分钟用python采集网页

一分钟用python采集网页

作者: comboo | 来源:发表于2016-06-06 16:08 被阅读812次

需要

  • html通讯原理
  • 安装python的requests

原理

根据http协议,模拟数据的传输

找到headers头信息,url,通讯方法(如果是post方法,需要找到post的数据)

如何寻找相应的数据

通过requests包模拟请求

代码

import requests.
headers = {
'User-agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.97 Safari/537.36'
}
html  = requests.get('http://www.baidu.com',headers = headers)
print html.content

相关进阶:

requests文档

相关文章

网友评论

    本文标题:一分钟用python采集网页

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