check if html tag has a child in python

Viewed 18

well i have this code :

js_code = "document.getElementsByTagName('a').hasChildNodes()"
js_b = js2py.eval_js(js_code)

if js_b == False : 
 names =  driver.find_elements(By.TAG_NAME, 'a')
 names = [n.text for  n in names ]

for n in names: 
   if len(n) > 4 :
     i_names.append(n)
     print("***")
     print(len(n))
     print("***")

I'm trying to scrape an HTML page with python selenium and I want to scrape the text in the a tag that has no child.

0 Answers
Related