Trouble with XPath
Hi,
I'm hoping one of you might be able to help me out with some fixes I wanted to make to an outdated translator. It is for the economist site (http://economist.com). I have found the xpath of the element I want to use for the title but when I run the translator it fails and reports that the doc.evaluate is returning null. I find this to be odd since I can copy these lines into firebug and they find the text perfectly, the translator also works from within scaffold. These are the lines:
var flyTitle = doc.evaluate('/html/body/div[2]/div[3]/div/div/div/h2', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var headline = doc.evaluate('/html/body/div[2]/div[3]/div/div/div/div', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
newItem.title= flyTitle + ': ' + headline;
Is there something different about the context in which the translor runs with would cause it's behaviour to vary from that observed in firebug and scaffold? I have properly set up namespace and nsResolver in my function. The test page I've been using is http://www.economist.com/node/18065683.
I'm hoping one of you might be able to help me out with some fixes I wanted to make to an outdated translator. It is for the economist site (http://economist.com). I have found the xpath of the element I want to use for the title but when I run the translator it fails and reports that the doc.evaluate is returning null. I find this to be odd since I can copy these lines into firebug and they find the text perfectly, the translator also works from within scaffold. These are the lines:
var flyTitle = doc.evaluate('/html/body/div[2]/div[3]/div/div/div/h2', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
var headline = doc.evaluate('/html/body/div[2]/div[3]/div/div/div/div', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
newItem.title= flyTitle + ': ' + headline;
Is there something different about the context in which the translor runs with would cause it's behaviour to vary from that observed in firebug and scaffold? I have properly set up namespace and nsResolver in my function. The test page I've been using is http://www.economist.com/node/18065683.
For instance I used
doc.evaluate('//h2[@class="fly-title"]', doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext().textContent;
Which, again, works nicely in firebug and scaffold but fails miserably in zotero proper:
doc.evaluate("//h2[@class=\"fly-title\"]", doc, nsResolver, XPathResult.ANY_TYPE, null).iterateNext() is null
So the issue of which xpath I use aside I am still not getting the consistent results I would like.
And this discussion should probably take place on zotero-dev, not the forum.
And I'm calling it a night-- more feedback in the morning if you still need help.
I am looking into the Aleph translator and I suspect that some of the problems are related to scraping an iframe with an "AddThis" box. Can you show me some light on how to avoid this? Thanks! (pointing to a related discussion link is also welcome!)
As before, please direct further questions to zotero-dev.