最近正在学习Golang,刚刚结束的项目中使用golang的chromedp完成了无头浏览器截屏的功能。

于是博主就想到是不是可以用无头浏览器去访问搜狗站长平台/360站长平台,实现自动登录并且提交网址的功能。

现在已经实现了访问网页自动点击登陆并输入账号密码,可是一个IP访问几次后就需要验证码,跳过验证码这里是个难点,网上搜了半天得到的结果都不满意。

最后发现了百度提供的免费API-通用文字识别接口,申请试用了下,免费版准确率不高,且一些歪歪扭扭的验证码根本识别不到,不知道高精度版是否能识别。

这里先记录一下免费版的调用代码,感兴趣的小伙伴也可以用本站的API进行测试。

百度云文字识别API文档:https://cloud.baidu.com/doc/OCR/s/1k3h7y3db

本站接口地址:http://www.mysqlschool.cn/api/Imagetotext.php?imgurl=*****

注:*****为图片地址

例:http://www.mysqlschool.cn/api/Imagetotext.php?imgurl=http://www.mysqlschool.cn/wp-content/uploads/2021/12/1640227284-6dcfcdc994eaa89.png

PHP调用源码👇👇👇

$imgurl=$_GET['imgurl'];
if(!$imgurl){
    echo("无图可查");exit();
}

$url = 'https://aip.baidubce.com/oauth/2.0/token';
$post_data['grant_type']       = 'client_credentials';
$post_data['client_id']      = '你的 Api Key';
$post_data['client_secret'] = '你的 Secret Key';
$o = "";
foreach ( $post_data as $k => $v ) 
{
	$o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
$res = request_post($url, $post_data);

$token = json_decode($res)->access_token;
$url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=' . $token;
$img = file_get_contents($imgurl);
$img = base64_encode($img);
$bodys = array(
    'image' => $img
);
$res = request_post($url, $bodys);

echo($res);

/**
* 发起http post请求(REST API), 并获取REST请求的结果
* @param string $url
* @param string $param
* @return - http response body if succeeds, else false.
*/
function request_post($url = '', $param = '')
{
    if (empty($url) || empty($param)) {
        return false;
    }

    $postUrl = $url;
    $curlPost = $param;
    // 初始化curl
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $postUrl);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    // 要求结果为字符串且输出到屏幕上
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    // post提交方式
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
    // 运行curl
    $data = curl_exec($curl);
    curl_close($curl);

    return $data;
}

更多IT相关的内容请到源站查看:MySQL研究院