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: true or false

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

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -