1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import requests # 发起请求的库 import re # 根据站点地图获取链接 def get_urls(sitemap): response = requests.get(url=sitemap) urls = re.findall('<loc>(.*?)</loc>', response.text) return urls # 提交到必应 def submit_bing(site_url: str, url_list: list, api_key: str): try: response = requests.post(url=f"https://ssl.bing.com//webmaster/api.svc/json/SubmitUrlbatch?apikey={api_key}", json={ 'siteUrl': site_url, 'urlList': url_list }, headers={ 'Host': 'ssl.bing.com', 'Content-Type': 'application/json; charset=utf-8', }) print(response.status_code) except Exception as e: print('e') finally: if response.status_code == 200 and response.json().get('d') is None: print('推送成功:') for i in url_list: print(i) else: print('推送失败:推送配额不足,前往https://www.bing.com/webmasters/submiturl查看配额') if __name__ == '__main__': apiKey = '3b992effa69a4cf6ba44227d7f34b4ed' siteUrl = 'https://www.bidaoge.com/' limit = 100 # 每日提交配额 urlList = get_urls('https://www.bidaoge.com/sitemap/sitemap_2.xml')[-100:] # 提交最新的网站 submit_bing(site_url=siteUrl, url_list=urlList, api_key=apiKey) |
运行环境pyton3.8.5,脚本百分之百没问题,运行出错请自行百度,应该是运行环境搭建问题
阅读全文
评论前必须登录!
立即登录 注册