News for hackers. Stuff that matters.
Re:Using YQL to grab HN links by chaosmachine on Saturday May 02, 2009 @06:55PM (#590294)
The 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/

Re:Using YQL to grab HN links by thorax on Saturday May 02, 2009 @08:28PM (#590364)
You know, honestly, I wasn't grokking much about how cool YQL could be until I saw this example. This helps a lot. Thanks.
Re:Using YQL to grab HN links by henning on Saturday May 02, 2009 @08:38PM (#590370)
I don't get it. Don't queries like that suffer from the same problems as normal screen scraping?
Re:Using YQL to grab HN links by jfarmer on Saturday May 02, 2009 @09:41PM (#590410)
Yeah, 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.

Re:Using YQL to grab HN links by Sephr on Saturday May 02, 2009 @07:46PM (#590328)
YQL 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.
Re:Using YQL to grab HN links by spullara on Saturday May 02, 2009 @07:50PM (#590334)
It offers JSONP instead so you can access any YQL content via Javascript in a browser via script nodes.
Re:Using YQL to grab HN links by Sephr on Sunday May 03, 2009 @01:41AM (#590592)
You still have to give Yahoo! complete control with that method. With XHR, Yahoo! has no control over your webpage.
Re:Using YQL to grab HN links by spullara on Sunday May 03, 2009 @06:14AM (#590757)
It only it works in a few browsers but doesn't seem like it would hurt anything to add it. Thanks for the suggestion!
Re:Using YQL to grab HN links by sachinag on Sunday May 03, 2009 @10:51AM (#590874)
I love how HN is the only site where "[x] would be cool" turns into a feature request implemented by the vendor.
Re:Using YQL to grab HN links by spullara on Sunday May 03, 2009 @02:30PM (#591092)
Nah, we do the same thing for things suggested on Twitter :)
Re:Using YQL to grab HN links by rjurney on Saturday May 02, 2009 @09:48PM (#590419)
Just 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?

Re:Using YQL to grab HN links by tectonic on Sunday May 03, 2009 @03:33AM (#590697)
For another approach, with a structure editor, check out http://parselets.com
Re:Using YQL to grab HN links by hsuresh on Sunday May 03, 2009 @02:41AM (#590652)
which newspaper website was it?
Re:Using YQL to grab HN links by 3ds on Sunday May 03, 2009 @08:28AM (#590805)
in 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
Re:Using YQL to grab HN links by yeahit on Sunday May 03, 2009 @04:01AM (#590713)
If 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.)
Re:Using YQL to grab HN links by sarp on Sunday May 03, 2009 @07:23AM (#590782)
This shows all urls on HN including images etc. whereas the original post demonstrates retrieving only linked articles
Re:Using YQL to grab HN links by yeahit on Sunday May 03, 2009 @09:25AM (#590821)
You can filter that with another grep for example:

  wget -O- news.ycombinator.com | grep -o 'title"><a href="[^"]*' | grep -o http.*
Re:Using YQL to grab HN links by ghempton on Sunday May 03, 2009 @01:08AM (#590563)
Does it first convert the page to valid xhtml and then perform the xpath or does it rely on the website to be well-marked?
Re:Using YQL to grab HN links by simonw on Sunday May 03, 2009 @02:54AM (#590663)
It works against not-well-formed markup.
Re:Using YQL to grab HN links by found_dead on Monday May 04, 2009 @12:27PM (#592597)
I 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.