python--爬虫--获取和解析存储网页内容--以薄荷网为例(9)
- UID
- 1066743
|
python--爬虫--获取和解析存储网页内容--以薄荷网为例(9)
实例3: 百度/360搜索关键词提交爬虫
搜索关键词提交的接口:
https://www.baidu.com/s?ie=UTF-8&wd=keyword
1
通过requests的params参数,构造查询参数
完整的代码
import requests
keyword = "张学友"
url = "http://www.baidu.com/s?ie=UTF-8"
try:
kv = {"wd":keyword}
r = requests.get(url, params = kv)
print(r.request.url)
r.raise_for_status()
print(len(r.text))
print(r.text)
except:
print("爬取失败") |
|
|
|
|
|