Skip to content
Advertisement

Extract href by class Selenium Python

Im trying to get all hrefs that are found the a specific class next to them. Im not really familiar with HTML so I’m having some trouble.

Basically the HTML code in inspect is:

JavaScript

I’m using the find_elements command to find all lines that include the class “notranslate _0imsa ” like this:

JavaScript

I then extract all hrefs from “links” with the following command:

JavaScript

When I try to print the lengths of “users” and “links” they all show 0.

Advertisement

Answer

Compound class names (one separated with spaces: notranslate _0imsa) are not permitted.

Selenium wouldn’t be able to find those elements this way.

Try this instead:

JavaScript

NOTE: you have to import By:

JavaScript

find_elements_by_class_name, find_element_by_xpath etc. are deprecated

Read more about compound class names in this article: Selenium compound class names not permitted

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement