Objective-C HTML parsing. Get all text between tags -


i using hpple try , grab torrent description thepiratebay. currently, i'm using code:

nsstring *path = @"//div[@id='content']/div[@id='main-content']/div/div[@id='detailsouterframe']/div[@id='detailsframe']/div[@id='details']/div[@class='nfo']/pre/node()"; nsarray *nodes = [parser searchwithxpathquery:path]; (tfhppleelement * element in nodes) {     nsstring *postid = [element content];     if (postid) {         [texts appendstring:postid];     } } 

this returns plain text, , not of url's screenshots. there anyway links , other tags, not plain text? piratebay fomratted so:

<pre>     <a href="http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg" rel="nofollow">     http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg</a> more texts file </pre> 

that's easy job , did correctly!

what want content (or attribute) of a-tag, need tell parser want it.

just change xpath to

@"//div[@id='content']/div[@id='main-content']/div/div[@id='detailsouterframe']/div[@id='detailsframe']/div[@id='details']/div[@class='nfo']/pre/a" 

(you missed a @ end , not need node())

output:

http://www.imdb.com/title/tt1904996/
http://leetleech.org/images/65823608764828593230.png
http://leetleech.org/images/44748070481477652927.png
http://leetleech.org/images/42024611449329122742.png

if want screenshot urls can like

nsmutablearray *screenshoturls = [[nsmutablearray alloc] initwithcapacity:0]; (int = 1; < nodes.count; i++) {     [screenshoturls addobject:nodes[i]]; } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -