1, Baidu keyword submission
If the teacher in accordance with the MOOC code to submit keywords, we will meet the security authentication Baidu
we open the browser, search Python, the following results
were observed URL features, start writing code
import requests
try:
# kv={'wd':'python'}
kv ={'ie':'utf-8','wd': 'Python','p_timestamp':'1583634916'}
ua = {'user-agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3'}
r=requests.get("http://www.baidu.com/s",headers=ua,params=kv)
print(r.request.url)
r.raise_for_status()
print(len(r.text))
except:
print("爬取失败")
2,360 keywords submit
No security verification submitted 360 keywords, keywords can be submitted directly
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("爬取失败")