xpath - HtmlUnit getByXpath returns null -
i coding groovy, however, don't believe language specific set of questions.
i have 2 questions
first question
i've run issue while using htmlunit. telling me trying grab null.
the page i'm testing on is: http://browse.deviantart.com/resources/applications/psbrushes/?order=9&offset=0#/dbwam4
my code:
client = new webclient(browserversion.firefox_3) client.javascriptenabled = false page = client.getpage(url) //coming null title = page.getbyxpath("//html/body/div[4]/div/div[3]/div/div/div/div/div/div/div/div/div/div/h1/a") println title
this prints out: []
is because page uses onclick()? if so, how around that? enabling javascript creates mess in cmd prompt.
second question
i wanting image having trouble because when attempt xpath (via firebug) shows as: //*[@id="gmi-resviewsizer_img"]
how handle that?
first answer:
/html/body/div[3]/div/div[3]/div/div/div/div/div/div/div/div/div/div/h1/a
your xpath off 1 in predicate filter 4th div
of body, should 3rd div
. appears html site can/does change when had origionally snagged xpath using firebug. may need adjust xpath accommodate potential change , less sensitive differences in document structure.
maybe this:
/html/body//div/h1/a
second answer: xpath listed work. may odd/short(and may not efficient), //
starts @ root node , looks throughout every node in tree, *
matches on element(to include img
) , []
predicate filter restricts have id
attribute who's value equals "gmi-resviewsizer_img".
there many other options xpaths work well. depend on how html structure changes. 1 works page referenced select img
:
/html/body/div/div/div/div/img[1]
Comments
Post a Comment