答案 0 :(得分:1)
您可以使用Jsoup来从雅虎抓取数据 下面是使用Jsoup从您提供的URL解析yahoo搜索的所有结果的代码
public static void main(String[] args) throws IOException {
String url = "https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777";
while (true) {
System.out.println("Getting data from " + url);
Document doc = Jsoup.connect(url).timeout(10000).userAgent("Mozilla/5.0").get();
Elements sections = doc.select("ol.searchCenterMiddle").first().select("div.options-toggle");
if (sections.isEmpty()) {
break;
}
for (Element section : sections) {
try {
System.out.println(section.getElementsByTag("a").first().text());
System.out.println(section.getElementsByTag("span").first().text() + " " + section.select("a.tri").first().text());
System.out.println();
} catch (Exception e) {
}
}
url = doc.select("a.next[href]").attr("href");
}
}