I used BeautifulSoup to scrape a website to save to a csv. When I open up the csv, there is only the header, title, and no data (the links that I scraped).
I already tried "lxml" so i switched to html.parser.
from bs4 import BeautifulSoup
import requests
import csv
page = requests.get('https://www.census.gov/programs-surveys/popest.html')
raw_html = page.text # declare the raw_html var
soup = BeautifulSoup(raw_html, 'html.parser') # parse the html
T = [["US Census Bureau Links"]] #Title
I = page.text
for link in soup.find_all('a', href=True):
print(link['href'])
with open("US_Census_Bureau_links.csv","w",newline="") as f:
cw=csv.writer(f)
cw.writerows(T)
cw.writerows(I)
f.close()
I get 8 pages full of links when I run it. but no links in the output csv.