Skip to content

Instantly share code, notes, and snippets.

@ben-n93
ben-n93 / snippet.py
Last active May 17, 2022 01:36
test.py
for tag in tags:
match_dictionary = {}
date = tag.find("span", {"class": "bday dtstart published updated"})
print(date.get_text())
for tag in tags:
match_dictionary = {}
date = tag.find("span",{"class":"bday dtstart published updated"}
for tag in tags:
match_dictionary = {}
date = tag.find("span", {"class": "bday dtstart published updated"})
match_dictionary["Date"] = date.get_text()
time = table.find("div", {"class": "ftime"})
match_dictionary["Time"] = time.get_text()
home_team = table.find("th", {"itemprop": "homeTeam"})
away_team = table.find("th", {"itemprop": "awayTeam"})
match_dictionary["Match"] = home_team.get_text() + " vs " + away_team.get_text()
matches.append(match_dictionary)
for match in matches:
print(match)
$ pip3 install requests, xlsxwriter, bs4
import requests
import xlsxwriter
from bs4 import BeautifulSoup
import requests
import xlsxwriter
from bs4 import BeautifulSoup
# Captures Wikipedia article response.
webpage = requests.get("https://en.wikipedia.org/wiki/2022_FIFA_World_Cup")
# Parses Wikipedia article HTML.
soup = BeautifulSoup(webpage.text, "html.parser")
tags = soup.find_all("div", {"class": "footballbox"})
for index, column in enumerate(COLUMN_NAMES):
worksheet.write(0, index , column)
row_index = 1
column_index = 0
for match in matches:
for value in match.values():
worksheet.write(row_index, column_index, value)
column_index += 1
row_index += 1
column_index = 0
import requests
from bs4 import BeautifulSoup
import xlsxwriter
COLUMN_NAMES = ["Date", "Time", "Match"]
# Captures Wikipedia article content.
content = requests.get("https://en.wikipedia.org/wiki/2022_FIFA_World_Cup")
# Parses Wikipedia article HTML.