Any help is appreciated!
soup1 = BeautifulSoup(updated_url, "lxml")
confStar = soup1.find_all('div', attrs={'data-testid': 'ConfidenceRating'})
print(confStar)
Above is the snippet of code I am having issues with. Every time I run my program it returns 15 divs when I only want one. I know it is running through each url item and returning all my values, but I cant figure out how I would go about only showing one pages results at a time.
import requests
import re
from bs4 import BeautifulSoup
import pprint
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/39.0.2171.95 Safari/537.36'}
games = {}
endUrl = 0
# ---------------------------PickWise Game Grabber-------------------------------------------------#
page = requests.get("https://www.pickswise.com/nfl/", headers={'Cache-Control': 'no-cache'})
soup1 = BeautifulSoup(page.content, 'lxml')
box = soup1.find_all("div", class_="predictions_eventGrid__xDIPy")
game_urls = []
bb = []
info = {f"Game{endUrl}": {"Record": {"team1": "",
"team2": ""},
"Projected W": "",
"Trust Factor": 0,
"+/-": 0,
}
}
# ----- Grabs all URLs for the upcoming games and adds it to game_urls list.
for time in box:
links = time.find('div', class_='EventGrid_eventContainer__39T3x')
for urls in links:
url = urls.get('href')
game_urls.append(url)
# ------------Visits each game url and populated dict with info------------------------#
for i in game_urls:
endUrl += 1
# ----- Finds URLS and fills data from webpage ---- #
updated_url = requests.get(f"https://www.pickswise.com{i}").text
soup = BeautifulSoup(updated_url, "lxml")
box = soup.find_all('div', class_="PredictionHeaderTeam_name__Pf64F")
record = soup.find('table', class_="PredictionEnhancedInfo_predictionEnhancedInfo__35ubN")
test = soup.find('div', class_="PredictionHeaderTeam_enhancedInfo__3lhgr")
# ------------Gets the confidence rating for each team on PickWise-------------------
soup1 = BeautifulSoup(updated_url, "lxml")
confStar = soup1.find_all('div', attrs={'data-testid': 'ConfidenceRating'})
print(confStar)
Below is the style of output I am looking for, yet it produces 15. (One for each NFL team)
[<div data-testid="ConfidenceRating"><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_tertiary__eho3l ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_empty__3yDPX ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_empty__3yDPX ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span></div>, <div data-testid="ConfidenceRating"><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_tertiary__eho3l ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_tertiary__eho3l ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_empty__3yDPX ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span></div>, <div data-testid="ConfidenceRating"><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_tertiary__eho3l ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_tertiary__eho3l ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span><span aria-label="icon-filled-star" class="Icon_icon__13A6L Icon_small__1lKlR Icon_icon-filled-star__1HGwq Icon_empty__3yDPX ConfidenceRating_star__pr0wt" data-testid="Icon" role="img"></span></div>]