'find_all() prints everythigh twice
I just started my first Web scraping project and out of some reason when I try to run this simple code, it prints all of the headlines twice. I have no Idea why and i tried without the for loop, but it still doesnt work.
from bs4 import BeautifulSoup
import requests
website = requests.get("https://www.mlb.com/twins")
soup = BeautifulSoup(website.content, "lxml")
headlines = soup.find_all("li", class_ = "p-headline-stack__headline")
for headline in headlines:
headline_text = headline.find("a", "p-headline-stack__link").text
print(headline_text)
this is the output:
'We rake': Twins mash six homers en route to first win Tap Recap: Buxton, Sánchez, Correa go deep in win ▶️ Injuries & Moves: Stashak injury update Buxton launches moonshot; bullpen brings Twins back to earth Twins' No. 29 prospect drives in 9 in HIgh-A debut Twins rookie gives batters that splinking feeling in debut 28 things to know about 28 Twins Season Pick ‘Em: Compete to win $100,000! Twins' Top 30 Prospects list 'We rake': Twins mash six homers en route to first win Tap Recap: Buxton, Sánchez, Correa go deep in win ▶️ Injuries & Moves: Stashak injury update Buxton launches moonshot; bullpen brings Twins back to earth Twins' No. 29 prospect drives in 9 in HIgh-A debut Twins rookie gives batters that splinking feeling in debut 28 things to know about 28 Twins Season Pick ‘Em: Compete to win $100,000! Twins' Top 30 Prospects list
out of some reason it repeats the headlines. Its probably a simple fix but i am new to programming and cant find the awnser.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|