使用requests库制作Python爬虫
2018-03-25 09:39
801 查看
使用python爬虫其实就是方便,它会有各种工具类供你来使用,很方便。Java不可以吗?也可以,使用httpclient工具、还有一个大神写的webmagic框架,这些都可以实现爬虫,只不过python集成工具库,使用几行爬取,而Java需要写更多的行来实现,但目的都是一样。
下面介绍requests库简单使用:
#!/usr/local/env python # coding:utf-8 import requests #下面开始介绍requests的使用,环境语言是python3,使用下面的网址作为参考 #http://www.sse.com.cn/market/bonddata/data/tb/ request_param = {'jsonCallBack': 'jsonpCallback6588', 'isPagination': 'true', 'sqlId': 'COMMON_BOND_XXPL_ZQXX_L', 'BONDTYPE': '地×××府债券', 'pageHelp.pageSize': '25', 'pageHelp.pageNo': '2', 'pageHelp.beginPage': '2', 'pageHelp.cacheSize': '1', 'pageHelp.endPage': '21'} user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.146 Safari/537.36' referer = 'http://www.sse.com.cn/market/bonddata/data/ltb/' #设置headers headers = {'User-Agent': user_agent, 'Referer': referer} #设置代理 proxy = { "http":"http://113.214.13.1:8000" } # 需要请求的URL地址 request_url = 'http://query.sse.com.cn/commonQuery.do?' #设置请求地址 response = requests.get(request_url, headers=headers, proxies=proxy, params=request_param); print(response.status_code) #文本响应内容 print(response.text) #json格式响应内容 print(response.json()) #二进制响应内容 print(response.content) #原始格式 print(response.raw)
您可能感兴趣的文章:
- python采用requests库模拟登录和抓取数据的简单示例
- python中requests库session对象的妙用详解
- Python中第三方库Requests库的高级用法详解
- Python3.6安装及引入Requests库的实现方法
- python中数据爬虫requests库使用方法详解
- 基于python requests库中的代理实例讲解
- 解决Python requests库编码 socks5代理的问题
- python利用requests库进行接口测试的方法详解
- mac下给python3安装requests库和scrapy库的实例
- Python requests库用法实例详解
- Python Requests库基本用法示例
相关文章推荐
- Python从零开始写爬虫(一)requests库使用
- python爬虫---Requests库的基本使用
- python3使用urllib模块制作网络爬虫
- Python爬虫 1.requests库的使用
- 数据爬虫(三):python中requests库使用方法详解
- 【Python3~爬虫工具】使用requests库
- 【python爬虫01】使用requests库模拟登录知乎
- python——爬虫学习——requests库的使用-(1)
- python爬虫学习---Requests库的使用
- 使用Python的urllib和urllib2模块制作爬虫的实例教程
- 数据爬虫(三):python中requests库使用方法详解
- Python 爬虫基础Requests库的使用(二十一)
- Python 爬虫---(5)Requests库的使用
- 使用python+selenium制作浏览器爬虫,彻底解决ajax异步加载问题(待更新)
- python中数据爬虫requests库使用方法详解
- 学习Python爬虫(三):Requests库入门级使用
- python3使用urllib模块制作网络爬虫
- python3 爬虫入门(二)requests库基本使用
- python爬虫学习笔记——使用requests库编写爬虫(1)
- python3使用urllib模块制作网络爬虫