Scraping/Parsing Google search results in Ruby

前端 未结 6 680
滥情空心
滥情空心 2021-01-01 05:37

Assume I have the entire HTML of a Google search results page. Does anyone know of any existing code (Ruby?) to scrape/parse the first page of Google search results? Ideal

6条回答
  •  攒了一身酷
    2021-01-01 05:50

    I'm unclear as to why you want to be screen scraping in the first place. Perhaps the REST search API would be more appropriate? It will return the results in JSON format, which will be much easier to parse, and save on bandwidth.

    For example, if your search was 'foo bar', you could just send a GET request to http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=foo+bar and handle the response.

    For more information, see "Google Search REST API" or Google's developer page.

提交回复
热议问题