Парсинг сайта . Данные из таблицы
Нужно получить данные из таблицы на сайте (Month,Price,Change) . Пишет что не находит имена в скобке Вот код:
import requests
url= "https://www.indexmundi.com/commodities/?commodity=robusta-coffee&months=360"
page = requests.get(url)
print(page)
soup = BeautifulSoup(page.content, 'html.parser')
lists = soup.find_all('section', class_="tblData")
for list in lists:
Price = list.find('td', class_="tblData__Price")
Month = list.find('td', class_="tblData__Month")
Change = list.find('td', class_="tblData__Change")
info = [Price, Month, Change]
print(info)```
Ответы (2 шт):
Автор решения: Сергей Ш
→ Ссылка
import pandas
ds = pandas.read_html("https://www.indexmundi.com/commodities/?commodity=robusta-coffee&months=360")
print(ds[1])
Month Price Change
0 Jul 1992 0.86 -
1 Aug 1992 0.86 0.00%
2 Sep 1992 0.90 4.65%
3 Oct 1992 0.97 7.78%
4 Nov 1992 1.05 8.25%
.. ... ... ...
355 Feb 2022 2.41 -0.82%
356 Mar 2022 2.29 -4.98%
357 Apr 2022 2.29 0.00%
358 May 2022 2.27 -0.87%
359 Jun 2022 2.29 0.88%
Автор решения: Сергей Ш
→ Ссылка
import requests
from bs4 import BeautifulSoup
page = requests.get("https://www.indexmundi.com/commodities/?commodity=robusta-coffee&months=360")
soup = BeautifulSoup(page.content, 'html.parser')
lists = soup.find('table', class_="tblData").find_all('tr')[1:]
for list in lists:
info = [x.text for x in list.find_all('td')]
print(info)