title: Scraping and parsing Google search results using Python
body: <p>I asked a <a href="https://stackoverflow.com/questions/7722876/web-mining-or-scraping-or-crawling-what-tool-library-should-i-use">question</a> on realizing a general idea to crawl and save webpages.
  Part of the original question is: how to crawl and save a lot of "About" pages from the Internet.</p>
  
  <p>With some further research, I got some choices to go ahead with both on scraping and parsing (listed at the bottom).</p>
  
  <p>Today, I ran into another <a href="https://stackoverflow.com/questions/1539798/scraping-parsing-google-search-results-in-ruby">Ruby discussion</a> about how to scrape from Google search results. This provides a great alternative for my problem which will save all the effort on the crawling part.</p>
  
  <p>The new <strong>question</strong> are: in Python, to <strong>scrape</strong> Google search results for a given keyword, in this case "About", and finally get the links for further parsing.
  What are the best choices of methods and libraries to go ahead with? (in measure of easy-to-learn and easy-to-implement). </p>
  
  <p>p.s. in <a href="http://goohackle.com/tools/google-parser/" rel="noreferrer">this website</a>, the exactly same thing is implemented, but closed and ask for money for more results. I'd prefer to do it myself if no open-source available and learn more Python in the meanwhile.</p>
  
  <p>Oh, btw, advices for parsing the links from search results would be nice, if any. Still, easy-to-learn and easy-to-implement. Just started learning Python. :P</p>
  
  <hr>
  
  <p><strong>Final update</strong>, problem solved. Code using xgoogle, please read note in the section below in order to make xgoogle working.</p>
  
  <pre><code>import time, random
  from xgoogle.search import GoogleSearch, SearchError
  
  f = open('a.txt','wb')
  
  for i in range(0,2):
      wt = random.uniform(2, 5)
      gs = GoogleSearch("about")
      gs.results_per_page = 10
      gs.page = i
      results = gs.get_results()
      #Try not to annnoy Google, with a random short wait
      time.sleep(wt)
      print 'This is the %dth iteration and waited %f seconds' % (i, wt)
      for res in results:
          f.write(res.url.encode("utf8"))
          f.write("\n")
  
  print "Done"
  f.close()
  </code></pre>
  
  <hr>
  
  <p><strong>Note</strong> on xgoogle (below answered by Mike Pennington):
  The latest version from it's Github does not work by default already, due to changes in Google search results probably. These two replies (<a href="http://www.catonmat.net/c/27124" rel="noreferrer">a</a> <a href="http://www.catonmat.net/c/28907" rel="noreferrer">b</a>) on the home page of the tool give a solution and it is currently still working with this tweak. But maybe some other day it may stop working again due to Google's change/block.</p>
  
  <hr>
  
  <p>Resources known so far:</p>
  
  <ul>
  <li><p>For scraping, <a href="http://scrapy.org/" rel="noreferrer">Scrapy</a> seems to be a popular choice and a webapp called <a href="https://scraperwiki.com/" rel="noreferrer">ScraperWiki</a> is very interesting and there is <a href="https://github.com/onyxfish/fakerwiki" rel="noreferrer">another project</a> extract it's library for offline/local usage. <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="noreferrer">Mechanize</a> was brought up quite several times in different discussions too.</p></li>
  <li><p>For parsing HTML, <a href="http://www.crummy.com/software/BeautifulSoup/" rel="noreferrer">BeautifulSoup</a> seems to be the one of the most
  popular choices. Of course. <a href="http://lxml.de/index.html" rel="noreferrer">lxml</a> too.</p></li>
  </ul>