0

How should I access text from 'strong' and 'span' tags nested under 11 'li' tags in the picture below using Python Selenium?

I'm looking to store the output in dict format: {"Name": Name, Address: No.250/1, 16th and 17th cross..., State: Karnataka, City: Bangalore}

Here's the HTML:

enter image description here

Here's my code:

for elem in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"[id^='arrowex']"))):
    NGO_element = driver.find_element_by_class_name("faq-sub-content exempted-result")
    NGO_name = (driver.find_element_by_class_name("fc-blue fquph")).text.replace(NGO_name_pancard.text, '')
    NGO_name_pancard = driver.find_element_by_class_name("pan-id")
    ul = driver.find_element_by_class_name("exempted-detail")
    for item in (ul.find_elements_by_tag_name("li")):
2
  • Share your URL for more details. Commented Feb 19, 2018 at 11:35
  • Please read why a screenshot of HTML or code or error is a bad idea. Consider updating the Question with formatted text based relevant HTML, code trials and error stack trace. Commented Feb 19, 2018 at 11:55

1 Answer 1

1

Try below code to get values from strong and span nodes of each li as key-value pair:

data = {}
for item in (ul.find_elements_by_tag_name("li")):
    data[item.find_element_by_tag_name('strong').text] = item.find_element_by_tag_name('span').text

The output of data should looks like {'Address': 'No.250/1, 16th and 17th cross...', 'State': 'Karnataka', 'City': 'Bangalore', etc}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.