5 ms·
Using YQL to grab HN links
- chaosmachine 18y agoThe query is: select * from html where url="http://news.ycombinator.com/" and xpath='//tr/td/a[substring(@href,1,4)="http"][@href!="http://ycombinator.com"]' You can play with it yourself here (needs yahoo login): http://developer.yahoo.com/yql/console/ http://developer.yahoo.com/yql/console/
- Sephr 18y agoYQL isn't that great server-side until they add an `Access-Control-Allow-Origin: *` header. I'm pretty disappointed that they completely disallow Javascript access.
- spullara 18y agoIt offers JSONP instead so you can access any YQL content via Javascript in a browser via script nodes.
- thorax 18y agoYou know, honestly, I wasn't grokking much about how cool YQL could be until I saw this example. This helps a lot. Thanks.
- henning 18y agoI don't get it. Don't queries like that suffer from the same problems as normal screen scraping?
- jfarmer 18y agoYeah, they're obviously brittle, but it's baby steps, y'know? I think it's pretty crazy that you can now scrape well-marked pages with a SQL-like syntax.
- rjurney 18y agoJust spent 20 minutes trying to grab all article links from a newspaper's website based on a url pattern. Failed. The docs could use some work. Anyone know how to do this?
- ghempton 18y agoDoes it first convert the page to valid xhtml and then perform the xpath or does it rely on the website to be well-marked?
- simonw 18y agoIt works against not-well-formed markup.
- yeahit 18y agoIf you use Linux or some other Unix, you can also do it with standard Unix tools: wget -O- news.ycombinator.com | grep -o http[^\"]* Personally, I prefer curl because it writes to stdout per default: curl news.ycombinator.com | grep -o http[^\"]* (After posting this, i noticed that HN cuts * signs at the end of a message. So I have to add this text here, or the last * would not be displayed.)
- 3ds 18y agoin python it would be like this (get BeautifulSoup first): -- import urllib2 from BeautifulSoup import BeautifulSoup ychtml = urllib2.urlopen('http://news.ycombinator.com/).read() for tdtitle in BeautifulSoup(ychtml).findAll("td", "title"): print tdtitle.a
- found_dead 18y agoI actually attended the talk on YQL at Barcamp Portland and it seems really powerful. You are basically able to use Yahoo's cloud servers and huge internet pipe for free with this service.