Advertisement
betauli

Untitled

Jun 29th, 2020
1,315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. from urllib.request import urlopen
  3. import pandas as pd
  4. import csv
  5.  
  6. page = open('ABC.html')
  7.  
  8. soup = BeautifulSoup(page.read(),'html.parser')
  9.  
  10. tables = soup.find_all('table')
  11.  
  12. output_rows = []
  13.  
  14. for table in tables:
  15.     for table_row in table.findAll('tr'):
  16.         columns = table_row.findAll('td')
  17.         output_row = []
  18.         for column in columns:
  19.             output_row.append(column.text)
  20.         output_rows.append(output_row)
  21.  
  22. df = pd.DataFrame(data=output_rows)
  23. df.to_csv(r'ABC.csv')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement