Live data from Hacker News

XPath tips from the web scraping trenches

blog.scrapinghub.com

1–6 of 6 posts

Re: XPath tips from the web scraping trenches

#4
post #2

There are some things in XPath that I really like. For example `x = ( a, b, c )' means: `(x == a or x == b or x == c)' which is quite handy sometimes. Also `(a,default)[1]' makes it easy to provide a default if a is null.

Thanks, that is novelty to me! I don't seem to get an example working, though. Is that XPath 2.0?

Re: XPath tips from the web scraping trenches

#5
post #2

There are some things in XPath that I really like. For example `x = ( a, b, c )' means: `(x == a or x == b or x == c)' which is quite handy sometimes. Also `(a,default)[1]' makes it easy to provide a default if a is null.

Thanks, that is novelty to me! I don't seem to get an example working, though. Is that XPath 2.0?

Yes, this is XPath 2.0. I don't bother with 1.0 if I can, because it is soooo far behind 2.0.

data:

xsl:

    
    

      
        
          
        
        
          
        
      
    

gives: false2

Re: XPath tips from the web scraping trenches

#6
post #5

Earlier quoted context omitted.

Thanks, that is novelty to me! I don't seem to get an example working, though. Is that XPath 2.0?

Yes, this is XPath 2.0. I don't bother with 1.0 if I can, because it is soooo far behind 2.0. data: xsl: gives: false 2

That is very cool, indeed! =) I'm stuck with XPath 1.0 still, because XPath 2.0 hasn't found its way to lxml yet -- it seems to be quite a lot of work to implement it.