使用requests库制作Python爬虫
2019/7/15 1:00:48
本文主要是介绍使用requests库制作Python爬虫,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
使用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)
这篇关于使用requests库制作Python爬虫的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-04Python外包有哪些常见的主要库-icode9专业技术文章分享
- 2024-10-02基于深度学习的钢铁缺陷检测系统(yolov8、注意力机制、PyQt5界面、Python)
- 2024-10-01怎么用python搭建一个系统-icode9专业技术文章分享
- 2024-09-30Python基础入门教程
- 2024-09-30获取参数学习:Python中的基础教程
- 2024-09-30Python编程基础详解
- 2024-09-29点击加载学习:Python编程基础教程
- 2024-09-29数据科学五大Python前端库:第二部分
- 2024-09-27使用python 将ETH账户的资产打散
- 2024-09-26Python编程基础