简体   繁体   English

如何从Yahoo搜索中提取结果?

[英]How to extract results from a yahoo search?

I need to pass all the results retrieved by a yahoo search with an URL like that: 我需要使用这样的URL传递Yahoo搜索所检索到的所有结果:

https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777 https://es.search.yahoo.com/search?p=madrid&fr=yfp-t-777

and display them like this. 并像这样显示它们。

在此处输入图片说明

You can scrape data from yahoo using Jsoup 您可以使用Jsoup从Yahoo抓取数据
Here is the code using Jsoup to parse all the result from yahoo search with the URL you give 这是使用Jsoup解析yahoo搜索的所有结果以及您提供的URL的代码

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");
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM