'i want to scrape another class if first class is not found (n/a) in beautifulsoup, how to code this?
I'm scraping Indiegogo to see how many backers there are. However, because there are two different formats, it first scrapes the content for the first layout, but if this one is empty, I want to scrape another "class." how to do this?
backers = try_or(lambda: soup.find("span" ,class_="basicsGoalProgress-claimedOrBackers").find("span", {"class": "t-weight--medium"}).get_text())
if backers == "n/a":
try_or(lambda: soup.find("div", class_="basicsGoalProgress-amountTowardsGoal").contents[0].strip())
this is the coud i a using now but it still shows n/a. i am a newbie with writing in python, so i hope someone could help me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|