Python批量查询关键词的搜索量-百度关键词批量查询搜索指数

    Python编程 wuya 47次浏览 已收录 0个评论

    Python批量查询关键词的搜索量代码如下:

    import requests
    import time
    import json
    id = 1
    import requests
    # response = requests.post('https://fengchao.baidu.com/hairuo/request.ajax?path=puppet%2FGET%2FPvSearchFunction%2FgetPvSearch&reqid=4b534c47-737c-4717-cb75-159244545780', headers=headers, data=data)
    
    def getpv(id,word):
      headers = {
        'sec-fetch-mode': 'cors',
        'origin': 'https://fengchao.baidu.com',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.75 Safari/537.36',
        'content-type': 'application/x-www-form-urlencoded',
        'accept': 'application/json',
        'referer': 'https://fengchao.baidu.com/fc/manage/new/user/25203752/mt/all/keyword',
        'authority': 'fengchao.baidu.com',
        'cookie': 'BIDUPSID=3ADBC5DB4EDCA8474B065029A50833D9; PSTM=1569726470; BAIDUID=251420D71D629FB588B717CDCE0B593B:SL=0:NR=10:FG=1; Hm_up_863779a7a3a15a5b2bff4338a01f002e=%7B%22uid_%22%3A%7B%22value%22%3A%2225203752%22%2C%22scope%22%3A1%7D%7D; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_WISE_SIDS=148077_149389_150724_147366_150967_150075_147089_150083_148193_148867_148211_148713_150744_147279_150038_150190_131861_149586_148754_147896_146575_148523_151032_127969_149908_146549_149535_142421_146653_146732_138426_149558_145994_131423_144658_147527_107314_148186_147715_149253_140311_146395_144966_150340_147546_148869_110085; uc_login_unique=bc40e48f59fd6d329e0cca7993f7bc9b; uc_recom_mark=cmVjb21tYXJrXzI1MjAzNzUy; BDUSS=DdYOXYxckF3SzNDaUdxNHRTU2xGVUJFU3AwNFkzUU1VbjlXTmV1eTV2dUdBQzVmSVFBQUFBJCQAAAAAAAAAAAEAAADP~WPFt7jg1rm-NLj2AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIZzBl-GcwZfR; SIGNIN_UC=70a2711cf1d3d9b1a82d2f87d633bd8a03442710811; __cas__st__3=0f84693e5e6535c52285b73f86c1667d3a44267c469e8c1d43d221d37ff5172eb87897dbb2476bf583d76051; __cas__id__3=25203752; __cas__rn__=344271081; CPID_3=25203752; CPTK_3=681900905; Hm_lvt_863779a7a3a15a5b2bff4338a01f002e=1593399890,1593563129,1594198556,1594258636; Hm_lpvt_863779a7a3a15a5b2bff4338a01f002e=1594258636; RT="z=1&dm=baidu.com&si=06mj07dyy39q&ss=kce4feed&sl=5&tt=3xr&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ld=6rk"',
        'sec-fetch-site': 'same-origin',
      }
      k='{"logid":-1,"entry":"kr_station_bidestimate_tab","bidWordSource":"wordList","regions":[1000,2000,3000,4000,5000,200000,8000,9000,10000,11000,12000,13000,14000,15000,16000,17000,18000,19000,20000,21000,22000,23000,24000,25000,26000,27000,28000,29000,30000,31000,32000,33000,34000,35000,36000,300000],"device":0,"limit":[0,100],"orderBy":"","order":"desc","campaignId":null,"adgroupId":null,"keywordList":[{"keywordName":"蝴蝶","price":null,"matchType":null,"phraseType":null}]}'
      k2=k.replace('蝴蝶',word)
      params = {
      'reqid':'4b534c47-320e-46aa-bc3a-158617114348',
      'eventId':'4b534c47-9fc4-446e-78ca-158617114347',
      'userid':'XXXX',
      'token':'XXXX',
      'path':'puppet/GET/PvSearchFunction/getPvSearch',
      'params':k2
      }
    
      response = requests.post('https://fengchao.baidu.com/hairuo/request.ajax', headers=headers, params=params, )
      html=response.content
      neirong=str(html,'utf-8')
      lowdata=json.loads(neirong)
      alldata=[]
    
      alldata.append(id)
      print(lowdata)
      if lowdata['data']['logid']==0:
        alldata.append(word)
        alldata2 = str(alldata) + '\n'
        print(alldata2)
        with open('infohaibaopv', 'a+', encoding='utf8')as g:
          g.writelines(alldata2)
      else:
        lowdata2=lowdata['data']['data'][0]
        keyword=lowdata2['keywordName']
        alldata.append(keyword)
        price=lowdata2['price']
        alldata.append(price)
        allpv=lowdata2['pv']
        alldata.append(allpv)
        pcpv=lowdata2['pcPv']
        alldata.append(pcpv)
        mobilepv=lowdata2['mobilePv']
        alldata.append(mobilepv)
        alldata2=str(alldata)+'\n'
        print(alldata2)
        with open('infohaibaopv','a+',encoding='utf8')as g:
          g.writelines(alldata2)
    id = 0
    for word in open('infohaibao',encoding='utf8'):
      try:
          print(word)
          id += 1
          getpv(id,word.strip())
    
      except:
        with open('errorkey', 'a+', encoding='utf8')as f:
          f.writelines(word)
        print('error词是{}请删除'.format(word))
    
    

    Python批量查询关键词的搜索量-百度关键词批量查询指数,都是垃圾代码


    学海无涯 , 版权所有丨如未注明 , 均为原创丨转载请注明Python批量查询关键词的搜索量-百度关键词批量查询搜索指数
    喜欢 (2)
    发表我的评论
    取消评论
    表情 加粗 删除线 居中 斜体 签到

    Hi,您需要填写昵称和邮箱!

    • 昵称 (必填)
    • 邮箱 (必填)
    • 网址