import requests
from bs4 import BeautifulSoup
import pandas as pd
website_url = requests.get('https://thereserve2.apx.com/mymodule/reg/prjView.asp?id1=1295').text
soup = BeautifulSoup(website_url,'html.parser')
table = soup.table
table_rows = table.find_all('tr')
data = {}
for tr in table_rows:
td = tr.find_all('td')
if len(td) != 2 : continue
data[td[0].text] = td[1].text.strip()
data_frame = pd.DataFrame([data], columns=data.keys())
data_frame.to_csv('output.csv', index=False)
Solution 1 :
Solution 2 :
import pandas as pd
df = pd.read_html(
"https://thereserve2.apx.com/mymodule/reg/prjView.asp?id1=1295", skiprows=1)[0]
new = pd.DataFrame([df.iloc[:, 4].to_list()], columns=df.iloc[:, 3].to_list())
print(new)
new.to_csv("data.csv", index=False)
Output: view-online
Problem :
I’m new to scraping and I can’t figure out how to get the data that I need from a certain website. Here is my code:
from lxml import html
import requests
from bs4 import BeautifulSoup
import pandas as pd
website_url = requests.get('https://thereserve2.apx.com/mymodule/reg/prjView.asp?id1=1295').text
soup = BeautifulSoup(website_url,'lxml')
print(soup.prettify())
table = soup.table
table_rows = table.find_all('tr')
for tr in table_rows:
td = tr.find_all('td')
row = [i.text for i in td]
print(row)
df = pd.DataFrame()
df['Rows'] = row
df
The output is showing the table like ['Column 1','Column 2']
so it should be easy to turn it into a exportable table but it isn’t working for some reason.