File size: 719 Bytes
10d2624
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from bs4 import BeautifulSoup
import pandas as pd

# Open and read the HTML file
with open("now_pac.html", 'r', encoding='utf-8') as file:
    html_content = file.read()


# Parse the HTML content
soup = BeautifulSoup(html_content, 'html.parser')


# Find all article elements
divs = soup.find_all('div', class_='image-slide-title')

# Initialize a list to store the data
data = []

for div in divs:
    name = div.text.strip().split(",")[0]
    office = div.text.strip().split(",")[1]
    # Append the extracted data to the list
    data.append({'Candidate': name, 'Office': office})

# Add to table
df = pd.DataFrame(data)
df["Endorsed by"] = "NOW PAC"

# write to csv
df.to_csv("now_endorsements.csv", index = False)