Skip to content
Texas lottery
import requests
from bs4 import BeautifulSoup
import pandas as pd
# Make a request to the Texas Lottery Commission website
url = 'https://www.txlottery.org/export/sites/lottery/Games/Power_Ball/Winning_Numbers/index.html'
response = requests.get(url)
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Extract the lottery numbers from the page
lottery_numbers = []
for row in soup.find_all('tr'):
cols = row.find_all('td')
cols = [col.text.strip() for col in cols]
lottery_numbers.append(cols)
# Create a DataFrame and save it to a CSV file
df = pd.DataFrame(lottery_numbers, columns=['date', 'numbers', 'powerball'])
df.to_csv('lottery_numbers.csv', index=False)
df
%%capture
!pip install seleniumfrom selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
# Create a new instance of the Firefox driver
driver = webdriver.Edge()
# Navigate to the Texas Lottery Commission website
url = 'https://www.txlottery.org/export/sites/lottery/Games/Power_Ball/Winning_Numbers/index.html'
driver.get(url)
# Parse the HTML content
soup = BeautifulSoup(driver.page_source, 'html.parser')
# Extract the lottery numbers from the page
lottery_numbers = []
for row in soup.find_all('tr'):
cols = row.find_all('td')
cols = [col.text.strip() for col in cols]
lottery_numbers.append(cols)
# Create a DataFrame and save it to a CSV file
df = pd.DataFrame(lottery_numbers, columns=['date', 'numbers', 'powerball'])
df.to_csv('lottery_numbers.csv', index=False)
# Close the browser
driver.quit()