这两天发现网站bing的流量突然起来了,就尝试看看情况。发现bing也支持API提交URL,就尝试拿之前百度的代码改了改,具体代码如下。
-
获取API,参考上图。
-
code
import requests as req
from bs4 import BeautifulSoup
all_link = []
origin_rul = 'https://www.emperinter.info/post-sitemap.xml' # 改成你自己的sitemap地址
r = req.get(origin_rul)
bs = BeautifulSoup(r.content, 'html.parser') #解析网页
hyperlink = bs.find_all(name = 'loc')
for h in hyperlink:
hh = h.string
all_link.append(hh)
url = f'https://ssl.bing.com/webmaster/api.svc/json/SubmitUrlbatch?apikey={YourKey}'
headers = {
"Content-Type": "application/json; charset=utf-8",
"Host": "ssl.bing.com",
}
# 组装成json数据
data = {
'siteUrl': "https://www.emperinter.info", # 改成你的网站地址
"urlList": all_link
}
try:
# 与 get 请求一样,r 为响应对象
r = req.post(url, json=data, headers=headers)
print(r.text)
except Exception as e:
print(e)
print("error")