gpt4 book ai didi

java - 阅读 Yahoo! 时出错答案网站

转载 作者:行者123 更新时间:2023-11-30 02:51:53 25 4
gpt4 key购买 nike

我想从文件 (a.txt) 中搜索我的一些查询并在 Yahoo! 中搜索它们回答站点,最后将检索到的结果写入另一个文件(b.txt)

我的代码如下:

public static void run() throws IOException {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("XX.XX.XX.XX", 8080));
LineNumberReader lnr = new LineNumberReader(new FileReader(new File("a.txt")));
lnr.skip(Long.MAX_VALUE);
int len = lnr.getLineNumber();
lnr.close();
for (int i = 0; i < len; i = i++) {
String ll = Files.readAllLines(Paths.get("a.txt")).get(i);
String l = URLEncoder.encode(ll, "UTF-8");
String surl = "https://answers.yahoo.com/search/search_result?p=" + l + "&sort=rel";
System.out.println("Search URL: " + surl);
URL url = new URL(surl);
InputStream in = url.openConnection(proxy).getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) {
PrintWriter pw = new PrintWriter(new FileOutputStream(new File("b.txt"), true));
pw.println(line);
pw.close();
}
rd.close();
}

但是,我收到如下错误:

Exception in thread "main" java.io.FileNotFoundException: https://answers.search.yahoo.com/search?p=How+a+13+year+old+boy+can+lose+weight%3F&sort=rel
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1834)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at Yahoo.run(Yahoo.java:117)
at Main.main(Main.java:36)

但是当我在浏览器网址中使用搜索字符串时,所需的结果显示在 Yahoo! 中网站。

最佳答案

错误不在代码中。阅读这个问题: Searching in yahoo using java

您必须使用BOSS API从现在开始进行搜索。看这个example并从那里开始。您必须更改进行连接并从雅虎获取的代码。祝一切顺利。

关于java - 阅读 Yahoo! 时出错答案网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38400050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com