利用 API 自动向搜索引擎提交网址
🕜 by pyList at 2020-02-28 00:34
前面已经介绍了向各大搜索引擎提交的经验,这次试着用 Go 语言去实践一下。也作个简单实践对比。拿 Google、Bing、Baidu 三大搜索引擎来比较,论简便性,B
字头的两个最简便,但从效果看,Google 最好。
百度
百度最简单,验证网站后,点击左侧 链接提交
就看到下面页面
发送一个 POST
请求就可以,下面是用 Go 的简单实现
func Baidu() {
sUrl := "http://data.zz.baidu.com/urls?site=https://pylist.com&token=xxxxxxxx"
buf := bytes.NewBufferString("https://pylist.com/t/1581940902")
req, err := http.NewRequest("POST", sUrl, buf)
if err != nil {
return
}
req.Header.Set("Content-Type", "text/plain")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
}
Bing
Bing 也类似,不过要生成 API 密钥
然后根据文档提交,下面是go 的实现
func Bing() {
sUrl := "https://ssl.bing.com/webmaster/api.svc/json/SubmitUrl?apikey=xxxxxxxx"
buf := bytes.NewBufferString(`{
"siteUrl":"https://pylist.com",
"url":"https://pylist.com/t/1581940902"
}`)
req, err := http.NewRequest("POST", sUrl, buf)
if err != nil {
return
}
req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
}
对于一些错误的处理:
{"ErrorCode":14,"Message":"ERROR!!! NotAuthorized"}
原因是域名未验证
{"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System.InvalidOperationException"}
URL 改用 https://ssl.bing.com
这个域名的提交次数很多,但有些域名却只有10条。
Google 最麻烦,估计是他家的东西多,关系复杂。但 Google 的文档也很具体,有时候也是因为太具体了,或是版本、页面改变,被弄晕是很正常。可以参考官方的文档慢慢实现。
文档在这里 https://developers.google.com/search/apis/indexing-api/v3/quickstart 18
下面简单提一下中间遇到的小问题。
在 https://search.google.com/search-console
给已验证的域名添加所有者时,不是“添加用户”
否则会出现下面的错误
{
"error": {
"code": 403,
"message": "Permission denied. Failed to verify the URL ownership.",
"status": "PERMISSION_DENIED"
}
}
在这之前,你可能会遇到这样的错误
Reason: required, Message: Login Required.
这个接口需要登录后操作,通过 oauth2
登录得到 token
,其有效时间是 1 小时。
需要在 google 的两个平台操作
- https://search.google.com/search-console 22 在这里把
client_email
添加到域名所有者 - https://console.cloud.google.com/ 4 这里最复杂了,慢慢摸索
更新
下面是帖子发表后截图更新
后台临时写了个 go 脚本,运行结果
提交后刷新 Google 搜索结果
意外发现,Bing 也秒收
疑问的是:在测试里我并没有向 bing 提交啊
总结
Google 真心还是不错!Bing 也良心!!
本文网址: https://pylist.com/t/1582821291 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
精彩评论
发表评论
相关推荐
小工具
标签
搜索引擎
网址
提交
主动
经验
useragent
蜘蛛
真假
识别
python
正则
关键字
搜索
tornado
异步
检测
目标
硬件加速
ubnt
er
固件
路由
虚拟机
virtualbox
很慢
网络
解决
text
sublime
内存
暴涨
乱码
vim
linux
中文
centos
不可
openwrt
usb
上网卡
共享
bbr
开启
dbutils
连接池
mysql
数据
国内
form
data
post
上传
u盘
mac
diskutil
格式化
顽固
最新版
wndr4300
升级
sqlite3
time
golang
timestamp
小结
时间
默认值
struct
设置
failed
load
devtools
sourcemap
chrome
自动更新
microsoft
关闭
app
store
登录
未知
静音
风扇
主机
笔记本
改造
低功耗
web
爬虫
服务器
组装
微信
尝鲜
视频
体验
cpu
debian
ubuntu
查看
温度
server
浏览
google
身份验证
authenticator
迁移
手机
webdriver
微博
selenium
gnu
安装
系统启动
编译
宅家
坑记
屏幕
动手
nginx
quic
抢先
最近发表
- Chrome 控制台 DevTools failed to load SourceMap 警告的消除方法
- Mac 关闭 Microsoft 自动更新
- Mac 登录 App Store 出现“发生了未知错误”的解决方法
- 老笔记本改造为无风扇静音主机方案
- 自己组装21瓦低功耗家庭爬虫、文件、web服务器
- 微信视频号尝鲜体验
- Ubuntu/Debian 查看CPU温度的方法
- 在Ubuntu/debian Server 系统使用Chrome 无头浏览模式
- 换手机后 Google 身份验证器 Google Authenticator 数据迁移的简单方法
- 使用Golang selenium WebDriver 自动登录微博
- 在 Ubuntu 或其它 GNU/Linux 系统下安装 Debian
- Mac 下制作 USB ubuntu/debian 系统启动、安装盘的几种方法
- ubuntu/debian 下自行编译 OpenWRT 固件
- 宅家自己动手换手机屏幕掉坑记
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- 在 Nginx 和 Golang web 上抢先体验 QUIC
最近浏览
- 路由 UBNT ER-X 官方固件升级及开启硬件加速的方法
- VirtualBox 虚拟机里网络很慢的解决方法
- 解决Sublime text 内存暴涨的问题
- linux vim 中文显示乱码的解决方法
- virtualbox centos 网络不可用问题的解决
- Openwrt 使用USB 4G 上网卡共享网络
- Openwrt 路由上开启BBR
- Python 用DBUtils 建立mysql 数据连接池
- OpenWrt 国内源
- python form-data post上传数据简便方法
- 在终端使用Mac diskutil 命令格式化顽固U盘
- WNDR4300 固件升级到 OpenWrt 最新版
- python SQLite3 连接池
- golang timestamp time 时间戳小结
- go struct 设置默认值
- Chrome 控制台 DevTools failed to load SourceMap 警告的消除方法
请问这个要怎么实现?能否加下QQ,我14977431,谢谢