python双标题组合源代码打包

admin 578 0

python双标题组合源代码打包-第1张图片-新锐站长网

调用:

get_double_title("如何让自己变得更帅")

原作者:惨绿少年

有需要就自己看教程安装吧,小编也不懂python

接口用的百度的,随便哪个搜索引擎都一样,实现比较简单,当然还有更复杂的方法,就是判断和主关键字的相关性然后进行组合,不过这个应该可以满足较多兄弟的要求了。

import requests
import re
import random

headers = {
            "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3",
            "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
            "Accept-Encoding": "gzip, deflate, br",
            "Cookie": "BIDUPSID=802ECA54D14472CAEBEC7EA9E16CD155; PSTM=1555851571; BD_UPN=12314353; __cfduid=d7698c0143e19486ff23d86828967f0961557982768; MSA_WH=375_812; BDUSS=JSQ2VkN3gtRFlNfkRUVX5VMHplfmxZY3dBYlp5WURYb3J6Nnl4cjkxRngtOWRkSUFBQUFBJCQAAAAAAAAAAAEAAAD24pa0vsTH08K-vNnAslkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHFusF1xbrBdSk; BAIDUID=802ECA54D14472CAEBEC7EA9E16CD155:SL=0:NR=10:FG=1; H_WISE_SIDS=135669_136721_127759_137755_136292_139405_136757_106370_128149_139148_120193_138489_138526_138878_137978_137690_131246_132551_137745_131518_118888_118860_118854_118827_118801_136687_107320_138883_136431_138844_139183_136862_138146_138114_139174_136195_137105_139273_139399_133847_138479_137735_138343_137467_138565_134256_138649_131423_139254_139246_136537_110085_139540_127969_139161_138303_137252_138806_139408_128201_138312_136635_138426_138562_136718_138941_138249_138317_139222; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_PS_PSSID=1460_21096_30211_30284; sug=3; sugstore=0; ORIGIN=0; bdime=0; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; delPer=0; BD_CK_SAM=1; PSINO=5; BDSVRTM=133; H_PS_645EC=f171lvrOOXdbNC1HfQSbbIm5ZYC0d1u10jbU0WaLgLRTZMcet9HI3m7WfdQpqCLdb%2FcL",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "Cache-Control": "max-age=0",
            "Host": "www.baidu.com",
            "Connection": "keep-alive",
            "Upgrade-Insecure-Requests": "1"}
url = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd={}"

def get_double_title(key):
    r = requests.get(url.format(key),headers=headers)
    con = r.text
    ret_titles = re.findall(r"""<a class="c-gap-top-xsmall item_3WKCf" href=".*?">(.*?)</a>""",con)
    # print(ret_titles)
    last_title = key+"({})".format(ret_titles[random.randint(0,3)])
    print(last_title)


标签: python 双标题组合 源代码 标题 组合

发表评论 (已有0条评论)

还木有评论哦,快来抢沙发吧~