爬虫-python调用百度API/requests
爬虫-python调用百度API/requests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
from urllib.request import urlopen
import requests import json
url = "http://apis.baidu.com/txapi/mvtp/meinv" #API req = requests.get(url) #request.get(url,param=param,headers = headers) headers = { 'apikey' : '自己的apikey' } #自己的apikey params = { 'num' : '5' } #请求参数(urlParam) : r = requests.get(url,params = params,headers = headers) (r)
(r) def SaveImage(ImageUrl,ImgName = 'default.jpg' ): response = requests.get(ImageUrl,stream = True ) image = response.content
dst = '/Users/Alan/desktop/BaiDUImages/' #路径 path = dst + ImgName ( 'Save the file:' ,path) with open (path, 'wb' ) as img: img.write(image) def run(): for line in r[ 'newslist' ]: title = line[ 'title' ] picUrl = line[ 'picUrl' ] SaveImage(picUrl,ImgName = title + '.jpg' ) run() |
第二课:
1 2 3 4 5 6 7 8 9 10 |
#!/usr/bin/env python3 #antuor:Alan import requests import re headers = { 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.86 Safari/537.36' } #审查元素 ,network 里的request headers,复制过来,变成字典形式url = 'http://www.cnblogs.com/wupeiqi/articles/4938499.html'
html = requests.get(url,headers = headers)
title = re.findall( 'href="(.*?)</a>' ,html.text) #查找所有以href="开头+</a>结尾的内容for i in title: print(i) |
输入结果:
http://www.cnblogs.com/wupeiqi/">Mr.Seven
http://www.cnblogs.com/">博客园
http://www.cnblogs.com/wupeiqi/">首页
http://i.cnblogs.com/EditPosts.aspx?opt=1">新随笔
http://msg.cnblogs.com/send/%E6%AD%A6%E6%B2%9B%E9%BD%90">联系
http://www.cnblogs.com/wupeiqi/rss">订阅
http://www.cnblogs.com/wupeiqi/rss"><img src="http://www.cnblogs.com/images/xml.gif" alt="订阅" />
http://i.cnblogs.com/">管理
http://www.cnblogs.com/wupeiqi/articles/4938499.html">Python之路【目录】
http://www.cnblogs.com/wupeiqi/articles/4906230.html">Python之路【第一篇】:Python简介和入门
http://www.cnblogs.com/wupeiqi/articles/4911365.html">Python之路【第二篇】:Python基础(一)
http://www.cnblogs.com/wupeiqi/articles/4943406.html">Python之路【第三篇】:Python基础(二)
http://www.cnblogs.com/wupeiqi/articles/4963027.html">Python之路【第四篇】:模块
http://www.cnblogs.com/wupeiqi/articles/5017742.html">Python之路【第五篇】:面向对象及相关
http://www.cnblogs.com/wupeiqi/articles/5040823.html" target="_blank">Python之路【第六篇】:Socket
http://www.cnblogs.com/wupeiqi/articles/5040827.html" target="_blank">Python之路【第七篇】:线程、进程和协程
http://www.cnblogs.com/wupeiqi/articles/5095821.html">Python之路【第八篇】:堡垒机实例以及数据库操作
http://www.cnblogs.com/wupeiqi/articles/5132791.html" target="_blank">Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
http://www.cnblogs.com/wupeiqi/articles/5237672.html" target="_blank">Python之路【第十五篇】:Web框架
http://www.cnblogs.com/wupeiqi/articles/5237704.html" target="_blank">Python之路【第十六篇】:Django【基础篇】
http://www.cnblogs.com/wupeiqi/articles/5246483.html" target="_blank">Python之路【第十七篇】:Django【进阶篇】
http://www.cnblogs.com/wupeiqi/articles/5341480.html" target="_blank">Python之路【第十八篇】:Web框架们
http://www.cnblogs.com/wupeiqi/articles/4949995.html" target="_blank">计算器源码
http://www.cnblogs.com/wupeiqi/articles/4980620.html" target="_blank">装饰器
http://i.cnblogs.com/EditArticles.aspx?postid=4938499" rel="nofollow">编辑
#" onclick="AddToWz(4938499);return false;">收藏
第三课:对异步加载的网页,可以用post向提交数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#!/usr/bin/env python3 #antuor:Alan import requests import re
url = 'http://www.crowdfunder.com/browse/deals'
data = { 'entities_only' : 'true' , #是字符串,不是布尔值 'page' : '1' #是字符串 1 ,不是数字
}
html = requests.post(url,data = data) #用post方法,不用get title = re.findall( '"card-title">(.*?)</div>' ,html.text) for each in title: (each) |
- 爬虫-python调用百度API/requests
- python爬虫之百度API调用方法
- Python爬虫之百度API调用
- Python调用百度API之天气查询
- python 3调用百度OCR API实现剪贴板文字识别
- Linux python PyQt5调用百度API实现图片文字转换
- 【Python】调用百度REST API实现语音识别
- python百度api调用
- Python 调用百度API
- Python 3调用百度OCR API实现剪贴板文字识别
- python调用新浪API爬虫
- 实践项目五:python调用百度API实现自动检测翻译
- python爬虫︱百度百科的requests请求、百度URL格式、网页保存、爬虫模块
- 基于百度API接口的python数据爬虫解析1【笔记】
- Python3--批量爬取数据之调用百度api进行翻译
- python调用百度REST API实现语音识别
- python爬虫入门教程--利用requests构建知乎API(三)
- 【Python】调用百度REST API实现语音识别
- python3.6 通过调用 阿里云 API (非SDK方式) 16ca 查询 可用区 例子
- 调用百度“搜索建议(BaiduSuggestion)”的 API