Java检测百度是否收录网站url、推送百度的工具类

2024.07.15 20:23
阅读 7
import com.alibaba.fastjson.JSONObject;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
public class BaiduEmbodyTool {
public static Boolean check(String ---) {
try {
Connection.Response ---- = Jsoup.connect("https://www.baidu.com/s?wd=" + ---)
.timeout(60000)
.method(Connection.Method.GET)
.maxBodySize(0)
.followRedirects(false)
.execute();
String ---- = new String(----.bodyAsBytes());
if( !"".equals(----) ){
Document --- = Jsoup.parse(----);
Element ------- = ---.getElementsByClass("content_none").first();
return null == -------;
}else{
return false;
}
} catch (Exception -) {
-.printStackTrace();
return false;
}
}
public static JSONObject publish(String ----, String -----, String[] ----){
String ----- = "";
for(String - : ----){
----- += - + "\n";
}
PrintWriter --- = null;
BufferedReader -- = null;
String ------ = "";
try {
URLConnection ---- = new URL("http://data.zz.baidu.com/urls?site=" + ---- + "&token=" + -----).openConnection();
----.setRequestProperty("Host", "data.zz.baidu.com");
----.setRequestProperty("User-Agent", "curl/7.12.1");
----.setRequestProperty("Content-Type", "text/plain");
----.setDoInput(true);
----.setDoOutput(true);
--- = new PrintWriter(----.getOutputStream());
---.print(-----.trim());
---.flush();
-- = new BufferedReader(new InputStreamReader(----.getInputStream()));
String ----;
while ((---- = --.readLine()) != null) {
------ += ----;
}
return JSONObject.parseObject(------);
} catch (Exception -) {
-.printStackTrace();
return null;
} finally {
if(---!=null){
try {
---.close();
}catch (Exception -){
-.printStackTrace();
}
}
if(--!=null){
try {
--.close();
}catch (Exception -){
-.printStackTrace();
}
}
}
}
}
学无止境 学至分享
大家好,我是对IT技术着迷的家伙。只为帮助广大程序猿,将正确的内容带给需要的人。

学至分享
微信小程序
随时随地、想看就看

GM记账助手
微信小程序
方便快捷、界面美观

eView
微信小程序
漂亮的跨平台组件库
文章标签
推荐工具