<p>I would like to get data from from different webpages such as addresses of restaurants or dates of different events for a given location and so on. What is the best library I can use for extracting this data from a given set of sites? </p>

[{'answer_id': 67078, 'author': 'Silas', 'author_id': 8019, 'author_profile': 'https://Stackoverflow.com/users/8019', 'pm_score': 0, 'selected': False, 'text': '<p>What language do you want to use?</p>\n\n<p>curl with awk might be all you need.</p>\n'}, {'answer_id': 67099, 'author': 'Jim', 'author_id': 8427, 'author_profile': 'https://Stackoverflow.com/users/8427', 'pm_score': 0, 'selected': False, 'text': '<p>You can use <a href="http://tidy.sourceforge.net/" rel="nofollow noreferrer">tidy</a> to convert it to XHTML, and then use whatever XML processing facilities your language of choice has available.</p>\n'}, {'answer_id': 67101, 'author': 'Paul Dixon', 'author_id': 6521, 'author_profile': 'https://Stackoverflow.com/users/6521', 'pm_score': 1, 'selected': False, 'text': '<p>The Perl <a href="http://search.cpan.org/~petdance/WWW-Mechanize-1.34/lib/WWW/Mechanize.pm" rel="nofollow noreferrer">WWW::Mechanize</a> library is excellent for doing the donkey work of interacting with a website to get to the actual page you need.</p>\n'}, {'answer_id': 67106, 'author': 'klingon_programmer', 'author_id': 8501, 'author_profile': 'https://Stackoverflow.com/users/8501', 'pm_score': 0, 'selected': False, 'text': '<p>I\'d recommend <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow noreferrer">BeautifulSoup</a>. It isn\'t the fastest but performs really well in regards to the not-wellformedness of (X)HTML pages which most parsers choke on.</p>\n'}, {'answer_id': 67128, 'author': 'Hugh Buchanan', 'author_id': 9307, 'author_profile': 'https://Stackoverflow.com/users/9307', 'pm_score': 1, 'selected': False, 'text': '<p>I would use LWP (Libwww for Perl).  Here\'s a good little guide:  <a href="http://www.perl.com/pub/a/2002/08/20/perlandlwp.html" rel="nofollow noreferrer">http://www.perl.com/pub/a/2002/08/20/perlandlwp.html</a></p>\n\n<p>WWW::Scraper has docs here:  <a href="http://cpan.uwinnipeg.ca/htdocs/Scraper/WWW/Scraper.html" rel="nofollow noreferrer">http://cpan.uwinnipeg.ca/htdocs/Scraper/WWW/Scraper.html</a>\nIt can be useful as a base, you\'d probably want to create your own module that fits your restaurant mining needs.</p>\n\n<p>LWP would give you a basic crawler for you to build on.  </p>\n'}, {'answer_id': 67166, 'author': 'Drew Olson', 'author_id': 9434, 'author_profile': 'https://Stackoverflow.com/users/9434', 'pm_score': 3, 'selected': False, 'text': '<p>I think the general answer here is to use any language + http library + html/xpath parser. I find that using ruby + hpricot gives a nice clean solution:</p>\n\n<pre><code>require \'rubygems\'\nrequire \'hpricot\'\nrequire \'open-uri\'\n\nsites = %w(http://www.google.com http://www.stackoverflow.com)\n\nsites.each do |site|\n  doc = Hpricot(open(site))\n\n  # iterate over each div in the document (or use xpath to grab whatever you want)\n  (doc/"div").each do |div|\n    # do something with divs here\n  end\nend\n</code></pre>\n\n<p>For more on Hpricot see <a href="http://code.whytheluckystiff.net/hpricot/" rel="noreferrer">http://code.whytheluckystiff.net/hpricot/</a></p>\n'}, {'answer_id': 67194, 'author': 'Mike', 'author_id': 1115144, 'author_profile': 'https://Stackoverflow.com/users/1115144', 'pm_score': 3, 'selected': False, 'text': '<p>The HTML Agility Pack For .net programers is awesome.  It turns webpages in XML docs that can be queried with XPath.  </p>\n\n<pre><code>HtmlDocument doc = new HtmlDocument();\ndoc.Load("file.htm");\nforeach(HtmlNode link in doc.DocumentElement.SelectNodes("//a@href")\n{\nHtmlAttribute att = link"href";\natt.Value = FixLink(att);\n}\ndoc.Save("file.htm");\n</code></pre>\n\n<p>You can find it here.  <a href="http://www.codeplex.com/htmlagilitypack" rel="nofollow noreferrer">http://www.codeplex.com/htmlagilitypack</a></p>\n'}, {'answer_id': 67210, 'author': '8jean', 'author_id': 10011, 'author_profile': 'https://Stackoverflow.com/users/10011', 'pm_score': 2, 'selected': False, 'text': '<p>I personally like the <a href="http://search.cpan.org/perldoc?WWW::Mechanize" rel="nofollow noreferrer">WWW::Mechanize</a> Perl module for these kinds of tasks. It gives you an object that is modeled after a typical web browser, (i.e. you can follow links, fill out forms, or use the "back button" by calling methods on it).</p>\n\n<p>For the extraction of the actual content, you could then hook it up to <a href="http://search.cpan.org/perldoc?HTML::TreeBuilder" rel="nofollow noreferrer">HTML::TreeBuilder</a> to transform the website you\'re currently visiting into a tree of <a href="http://search.cpan.org/perldoc?HTML::Element" rel="nofollow noreferrer">HTML::Element</a> objects, and extract the data you want (the <code>look_down()</code> method of <code>HTML::Element</code> is especially useful).</p>\n'}, {'answer_id': 67277, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': True, 'text': '<p>If using python, take a good look at Beautiful Soup (<a href="http://crummy.com/software/BeautifulSoup" rel="noreferrer">http://crummy.com/software/BeautifulSoup</a>).</p>\n\n<p>An extremely capable library, makes scraping a breeze.</p>\n'}, {'answer_id': 67290, 'author': 'Daniel Spiewak', 'author_id': 9815, 'author_profile': 'https://Stackoverflow.com/users/9815', 'pm_score': 1, 'selected': False, 'text': "<p>There have been a number of answers recommending Perl Mechanize, but I think that Ruby Mechanize (very similar to Perl's version) is even better.  It handles some things like forms in a much cleaner way syntactically.  Also, there are a few frontends which run <em>on top</em> of Ruby Mechanize which make things even easier.</p>\n"}, {'answer_id': 589910, 'author': 'hamstar', 'author_id': 334975, 'author_profile': 'https://Stackoverflow.com/users/334975', 'pm_score': 2, 'selected': False, 'text': '<p>I personally find <a href="http://github.com/shuber/curl/tree/master" rel="nofollow noreferrer">http://github.com/shuber/curl/tree/master</a> and <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">http://simplehtmldom.sourceforge.net/</a> awesome for use in my PHP spidering/scraping projects.</p>\n'}, {'answer_id': 617222, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>what someone said.</p>\n\n<p>use ANY LANGUAGE.</p>\n\n<p>as long as you have a good parser library and http library, you are set.</p>\n\n<p>the tree stuff are slower, then just using a good parse library.</p>\n'}, {'answer_id': 9182385, 'author': 'user175099', 'author_id': 175099, 'author_profile': 'https://Stackoverflow.com/users/175099', 'pm_score': 2, 'selected': False, 'text': "<p>i think watir or selenium are the best choices. Most of the other mentioned libraries are actually HTML parsers, and that is not what you want... You are scraping, if the owner of the website wanted you to get to his data he'd put a dump of his database or site on a torrent and avoid all the http requests and expensive traffic.</p>\n\n<p>basically, you need to parse HTML, but more importantly automate a browser. This to the point of being able to move the mouse and click, basically really mimicking a user. You need to use a screencapture program to get to the captchas and send them off to decaptcha.com (that solve them for a fraction of a cent) to circumvent that. forget about saving that captcha file by parsing the html without rendering it in a browser 'as it is supposed to be seen'. You are screenscraping, not httprequestscraping. </p>\n\n<p>watir did the trick for me in combination with autoitx (for moving the mouse and entering keys in fields -> sometimes this is necessery to set of the right javascript events) and a simple screen capture utility for the captcha's. this way you will be most succesfull, it's quite useless writing a great html parser to find out that the owner of the site has turned some of the text into graphics. (Problematic? no, just get an OCR library and feed the jpeg, text will be returned). Besides i have rarely seen them go that far, although on chinese sites, there is a lot of text in graphics. </p>\n\n<p>Xpath saved my day all the time, it's a great Domain Specific Language (IMHO, i could be wrong) and you can get to any tag in the page, although sometimes you need to tweak it.</p>\n\n<p>What i did miss was 'reverse templates' (the robot framework of selenium has this). Perl had this in CPAN module Template::Extract, very handy. </p>\n\n<p>The html parsing, or the creation of the DOM, i would leave to the browser, yes, it won't be as fast, but it'll work all the time. </p>\n\n<p>Also libraries that pretend to be Useragents are useless, sites are protected against scraping nowadays, and the rendering of the site on a real screen is often necessery to get beyond the captcha's, but also javascript events that need to be triggered for information to appear etc. </p>\n\n<p>Watir if you're into Ruby, Selenium for the rest i'd say. The 'Human Emulator' (or Web Emulator in russia) is really made for this kind of scraping, but then again it's a russian product from a company that makes no secret of its intentions. </p>\n\n<p>i also think that one of these weeks Wiley has a new book out on scraping, that should be interesting. Good luck...   </p>\n"}]
['https://Stackoverflow.com/questions/67056', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/260/']