Reputation: 1
I was hoping to get some help on a problem that I'm having using BeautifulSoup.
import requests
from bs4 import BeautifulSoup
URL = "https://www.baseball-reference.com/players/s/sosasa01.shtml"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
results = soup.findAll("div",attrs={"class": "p1"})
second_results = soup.findAll("div",attrs={"class": "p2"})
for x in results:
print(x.find('p').text)
for x in second_results:
print(x.find('p').text)
Within class "p1", I'm trying to get the text in between all <p tags, but I can only get the first p within each class. I appreciate any help that you guys could provide.
photo of HTML I'm trying to scrape
Upvotes: 0
Views: 50
Reputation: 59593
You only find()
one <p>
instead of findAll()
<p>
:
for x in results:
for p in x.findAll('p'):
print(p.text)
print("--- second")
for x in second_results:
for p in x.findAll('p'):
print(p.text)
Upvotes: 1