python3爬虫post请求
2017-08-07 17:17
141 查看
python3
import urllib.requestfrom bs4 import BeautifulSoup
url=’http://zzk.cnblogs.com/s/blogpost?Keywords=python’
定义一个字典 作为header
send_header={‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8’,
‘Accept-Encoding’:’gzip, deflate, sdch’,
‘Accept-Language’:’zh-CN,zh;q=0.8’,
‘Connection’:’keep-alive’,
‘Cookie’:’__utma=59123430.1728851006.1499049847.1501827480.1501827480.1; __utmc=59123430; __utmz=59123430.1501827480.1.1.utmcsr=cnblogs.com|utmccn=(referral)|utmcmd=referral|utmcct=/; _ga=GA1.2.1728851006.1499049847; _gid=GA1.2.1963339392.1501827475; _gat=1’,
‘Host’:’zzk.cnblogs.com’,
‘Referer’:’http://zzk.cnblogs.com/s?t=b&w=python‘,
‘Upgrade-Insecure-Requests’:’1’,
‘User-Agent’:’Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36’
}
将heaer同步到url上
req=urllib.request.Request(url,headers=send_header)发起请求
r=urllib.request.urlopen(req)接收结果
s=r.read()BeautifulSoup解析
soup=BeautifulSoup(s,’html.parser’)print(soup.title)
相关文章推荐
- [Python爬虫] 使用urllib2库检测代理ip是否可用,并使用代理提交GET、POST请求
- 使用python进行爬虫学习(一)
- python 爬虫介绍
- 用Python+Selenium+PhantomJS实现采集动态数据的小爬虫
- 【学习笔记】Python爬虫-豆瓣电影所有短评
- 【Python爬虫】编写第一个爬虫
- 常用的 Python 爬虫技巧总结
- python3爬虫之猫眼电影Toop100获取
- WSWP(用 python写爬虫) 笔记四:实现缓存功能
- Python爬虫错误记录
- 基于Python的网络爬虫
- Python爬虫教程——入门一之爬虫基础了解
- python爬虫 爬去vamei的python快速教程
- Python爬虫博客
- Python爬虫 爬取翻译类网站
- python python 入门学习之网页数据爬虫搜狐汽车数据库
- [Python爬虫] 之十四:Selenium +phantomjs抓取媒介360数据
- python爬虫小练习之二:bs4库以及遇到的问题
- Python爬虫入门(8):Beautiful Soup的用法
- 用python写网络爬虫