运行效果:
代码:
# -*- coding: utf-8 -*- #百度移动端下拉词搜索 #@author 微信公众号:Python与SEO #20220524 by微信:huguo00289 import requests import json word='西安植物提取物厂家' url=f"https://m.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=wise&from=wise_web&net=1&os=1&sp=300&rm_brand=0&callback=jsonp2&wd={word}" r = requests.get(url=url) cont = r.content.decode('utf-8') # 获取返回的内容 # print(cont) res = cont[7: -1] res_json = json.loads(res) # json格式转换 keys=[] qs=res_json['g'] for q in qs: keys.append(q['q']) print(f'百度移动搜索下拉词:{keys}')