Edit: in this case the styling is added in by javascript after page load, so you have to wait for the whole page to load before scraping it, so Selenium is the way to go.
You can grab the page this way, just like Fazlul did it:
from bs4 import BeautifulSoup as bs
import time
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
driver.get("URL")
time.sleep(5)
html = bs(driver.page_source, 'html.parser')
then you can either use a CSS wildcard selector, then print out their innerText:
anchors = html.select('a[style*="color:red"]')
print([a.text for a in anchors])
OR
You could find all <a>
tags and put them in a list if they have that attribute.
anchors = html.select('a')
names = []
for a in anchors:
if 'style' in a.attrs and "color:red" in a.attrs['style']:
names.append(a.text)
Edit: I see an other user gave you a solution with BeautifulSoup and I'd like to add that if you're new to webscraping, but you plan on learning more, I'd also recommend learning to use BeautifulSoup. It's not only more powerful, but it's user base is much larger, so it's easier to find solutions for your problem.