0

I am using Python Selenium to scrape a webpage and am having difficulty finding the elements of interest. There are a large number of elements of interest on just one page and, ideally, I would like to extract all of them as strings in an array. The HTML code looks like this (the light blue highlighted portion is one of many elements I need to find):

enter image description here

So far, I have tried statements like these:

enter image description here

The first one returns an empty object. The second one returns unexpected results:

enter image description here

Any assistance is appreciated.

3
  • What exactly do you mean by strings in an array? You are locating WebElement objects, what you see is the to_string() representation. Do you want their text? an attribute? something else? Commented Oct 4, 2018 at 12:54
  • 1
    And you should post html and code as text, not images. Please read Why not upload images of code on SO Commented Oct 4, 2018 at 12:55
  • I am looking for everything highlighted in light blue saved as a string in a single element of an array. Commented Oct 4, 2018 at 13:02

1 Answer 1

1

If you want outerHTML of link saved as string, try

driver.find_element_by_css_selector('a.ng-binding').get_attribute('outerHTML')

If there are multiple links and you want result for each:

[link.get_attribute('outerHTML') for link in driver.find_elements_by_css_selector('a.ng-binding')]
Sign up to request clarification or add additional context in comments.

1 Comment

The second statement provided exactly what I needed. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.