Skip to content
Advertisement

Python / Selenium only print if class has a certain value + only print certain elements in html

I am coding a script that is going to test all free proxies available on: https://free-proxy-list.net/

On this site there is a list with all available proxies, and I managed to make my script print them all but, I only want to print the proxy value if https is enabled.

This is how the Html looks when https is enabled:

JavaScript

The "hx" class is set to yes: How can I make my code only print the proxy when the "hx" class value is "yes"?

And is there a way to only print the proxy and not “anonymous” or “Canada”

My code:

JavaScript

Example of current output:

JavaScript

Thanks for your help

Advertisement

Answer

You can filter it using xpath //td[@class='hx' and text()='yes']/.. , this xpath will only check for class hx and text()='yes'

Code:

JavaScript

Imports:

JavaScript

Output:

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