采集站seo怎么做?很多网站都是以双标题形式优化的,火车头+脚本形式可以满足,一段时间内,烨晟网络更新关于这方面的知识。今天,烨晟网络( www.yeshengweb.com )分享的内容为《采集站seo(火车头+Python脚本双标题代码)》。希望对大家有所帮助。
一、火车头与py脚本
火车头是支持py脚本的,火车采集器V9.2起将支持Python插件,python插件支持2.7和3.x版本,采集器默认自带2.7和3.4的示例代码,用户只需要稍微修改即可以完成自己的功能。Python插件功能将在V9.2版本中集成。
火车头不容易实现的功能,我们就用Python脚本来替代了。
二、Python脚本双标题代码
python版 双标题组合源代码(火车头插件!)调用:
get_double_title(“如何让自己变得更帅”)
接口用的百度的,随便哪个搜索引擎都一样,实现比较简单,当然还有更复杂的方法,就是判断和主关键字的相关性然后进行组合,不过这个应该可以满足较多兄弟的要求了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
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脚本双标题代码火车头插件
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。