爬虫-练习1
实例3
百度360搜索关键词提交
百度的关键词接口:
http://www.baidu.com/s?wd=keyword
360的关键词接口:
http://www.so.com/s?q=keyword
替换keyword就可以替换并提交关键词
#百度搜索全代码 import requests keyword='python' try: kv={'wd':keyword} r=requests.get('http://www.baidu.com/s',params=kv) print(r.request.url) r.raise_for_status() print(len(r.text)) except: print ('爬取失败')
结果:
http://www.baidu.com/s?wd=python
319959
360搜索全代码:
#360搜索全代码 import requests keyword='python' try: kv={'q':keyword} r=requests.get('http://www.so.com/s',params=kv) print(r.request.url) r.raise_for_status() print(len(r.text)) except: print ('爬取失败')
结果:
https://www.so.com/s?q=python
285407
invictus maneo!