馬老師開發(fā)必備之反射機制
def sug(self,word):
? ? ? ?url = 'https://fsug' ?# post請求
? ? ? ?# form表單的參數(shù) wd,參數(shù)值是任意的英文單詞
? ? ? ?data = {
? ? ? ? ? ?'kw': word ? ? ? ?}
? ? ? ?# 請求頭的User-Agent
? ? ? ?ua = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0'
? ? ? ?# 發(fā)起了post請求
? ? ? ?resp = requests.post(url, data=data, headers={'User-Agent': ua})
? ? ? ?if resp.status_code == 200:
? ? ? ? ? ?ret = resp.json() ?# 文本是json格式, json.loads(resp.text)
標簽: