Created
September 28, 2020 02:48
Парсер на BS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bs4 import BeautifulSoup | |
import pandas as pd | |
import csv | |
url = 'https://www.worldometers.info/world-population/' | |
requests.get (url) | |
page = requests.get (url) | |
soup = BeautifulSoup (page.text,'lxml') | |
##print (soup) | |
table_data = soup.find('table',class_='table table-striped table-bordered table-hover table-condensed table-list',) | |
headers = [] | |
for i in table_data.find_all('th'): | |
title = i.text | |
headers.append(title) | |
df =pd.DataFrame (columns = headers) | |
for j in table_data.find_all('tr')[1:]: | |
row_data = j.find_all ('td') | |
row = [tr.text for tr in row_data ] | |
lenght = len (df) | |
df.loc [lenght] = row | |
#print(headers) | |
print(df) | |
with open('data.csv','a') as f: | |
writer = csv.writer(f) | |
writer.writerow(df) | |
# Нужно дописать вывод результатов парсинга в график |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment