Getting the URLs for the first Google search results in a shell script

后端 未结 6 1991
北恋
北恋 2021-02-06 01:19

It\'s relatively easy to parse the output of the AJAX API using a scripting language:

#!/usr/bin/env python

import urllib
import json

base = \'http://ajax.goog         


        
6条回答
  •  抹茶落季
    2021-02-06 01:54

    I ended up using curl's --data-urlencode option to encode the query parameter and just sed for extracting the first result.

    curl -s --get --data-urlencode "q=example" http://ajax.googleapis.com/ajax/services/search/web?v=1.0 | sed 's/"unescapedUrl":"\([^"]*\).*/\1/;s/.*GwebSearch",//'

提交回复
热议问题