" tag using the href attribute?" />

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2021-11-05
@Dimpik

def get_content(source):
    soup = BeautifulSoup(source.text, "html.parser")
    Stock = soup.find_all('a', {"href": '/invest/stocks/MMM/'})
            
    Info = []
    item = Stock[0]
    name = item.find('span', {"class": "NameColumn__nameWrapper_177eF"}).get_text()
    Info.append({'Name': name})
    item = Stock[2]
    price = item.find(("span", {"class": "Money-module__money_3h4MT"})).get_text().split('\xa0')[0]
    Info.append({'Price': price})

    print(Info)

Frankly, all these garlands of methods are terrible and very unreliable.

S
Story teller, 2021-11-05
@Story teller

Stock = soup.find_all('a', href_='/invest/stocks/MMM/')
for row in Stock:
    print(row.text)

gives:
3M CompanyMMM
+3.13 $1.76%
$180.76

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question