1 import requests 2 Keyword = "Python" 3 try: 4 kv = {‘wd‘:Keyword} 5 r = requests.get("http://www.baidu.com/s",params=kv) 6 print(r.request.url) 7 r.raise_for_status() 8 print(len(r.text)) 9 except: 10 print("爬取失败")
输出:
http://www.baidu.com/s?wd=Python
461379
1 import requests 2 Keyword = "Python" 3 try: 4 kv = {‘q‘:Keyword} 5 r = requests.get("http://www.so.com/s",params=kv) 6 print(r.request.url) 7 r.raise_for_status() 8 print(len(r.text)) 9 except: 10 print("爬取失败")
输出:
https://www.so.com/s?q=Python
256963
原文:https://www.cnblogs.com/Shiko/p/10828171.html