Я пытаюсь получить данные из простой таблицы со следующего веб-сайта (https://bvmf.bmfbovespa.com.br/clube-de ... Idioma=pt- бр). Мне удалось получить данные с первой страницы, но, как мы видим, нумерация страниц не связана с URL-адресом, и я не смог их получить, хотя я мог найти кнопки внизу страницы «ProximoPaginacao» и «MeioPaginacao», но я не смог справиться с этой реализацией. Есть идеи?
import requests
from bs4 import BeautifulSoup
import pandas as pd
def extract_table_data(url, table_id):
try:
response = requests.get(url,verify=False)
response.raise_for_status()
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find('table', id=table_id)
if not table:
print(f"Table with ID '{table_id}' not found.")
return None
# Extract header row
header_row = [th.get_text(strip=True) for th in table.find_all('th')]
# Extract data rows
data_rows = []
for row in table.find('tbody').find_all('tr'):
data_rows.append([td.get_text(strip=True) for td in row.find_all('td')])
# Create DataFrame
df = pd.DataFrame(data_rows, columns=header_row)
return df
except requests.exceptions.RequestException as e:
print(f"Error during requests: {e}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
# Example usage
url = "https://bvmf.bmfbovespa.com.br/clube-de ... mento.aspx?
Idioma=pt-br" # Replace with the actual URL
table_id = "ctl00_contentPlaceHolderConteudo_grdAtivo_ctl01" # Replace with the actual
table ID
table_data = extract_table_data(url, table_id)
if table_data is not None:
print(table_data)
Подробнее здесь: https://stackoverflow.com/questions/793 ... references
Очистка таблицы динамических данных без простых ссылок ⇐ Python
Программы на Python
-
Anonymous
1737394846
Anonymous
Я пытаюсь получить данные из простой таблицы со следующего веб-сайта (https://bvmf.bmfbovespa.com.br/clube-de-investimento/clube-de-investimento.aspx?Idioma=pt- бр). Мне удалось получить данные с первой страницы, но, как мы видим, нумерация страниц не связана с URL-адресом, и я не смог их получить, хотя я мог найти кнопки внизу страницы «ProximoPaginacao» и «MeioPaginacao», но я не смог справиться с этой реализацией. Есть идеи?
import requests
from bs4 import BeautifulSoup
import pandas as pd
def extract_table_data(url, table_id):
try:
response = requests.get(url,verify=False)
response.raise_for_status()
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
table = soup.find('table', id=table_id)
if not table:
print(f"Table with ID '{table_id}' not found.")
return None
# Extract header row
header_row = [th.get_text(strip=True) for th in table.find_all('th')]
# Extract data rows
data_rows = []
for row in table.find('tbody').find_all('tr'):
data_rows.append([td.get_text(strip=True) for td in row.find_all('td')])
# Create DataFrame
df = pd.DataFrame(data_rows, columns=header_row)
return df
except requests.exceptions.RequestException as e:
print(f"Error during requests: {e}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
# Example usage
url = "https://bvmf.bmfbovespa.com.br/clube-de-investimento/clube-de-investimento.aspx?
Idioma=pt-br" # Replace with the actual URL
table_id = "ctl00_contentPlaceHolderConteudo_grdAtivo_ctl01" # Replace with the actual
table ID
table_data = extract_table_data(url, table_id)
if table_data is not None:
print(table_data)
Подробнее здесь: [url]https://stackoverflow.com/questions/79372190/scraping-dynamic-data-table-with-no-easy-references[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия