python - How to check if a element with specified xpath exists in the html document? -
i working on selenium in python , want know if element th e specified xpath exists in html page or not. how can it?
sample input:
chek_if_exists("xpath") output:
trueorfalse
lets have link:
link <-"http://www.skelbiu.lt/skelbimai/diplominiai-lt-4792675.html" first response:
response <- get(link) then, load document:
doc <- content(response,type="text/html", encoding = "utf-8") next, want extract header of advertisement. can check whether node exist checking condition if length of text not equal 0. if so, there such node or text "element not exist" returned.
name <- ifelse(length(xpathsapply(doc, "//title",xmlvalue))!=0, xpathsapply(doc, "//title",xmlvalue), "element not exist") the basic idea of minimal example employ ifelse statement , checking length of returned attribute content.
hth
Comments
Post a Comment