Как очистить таблицу из Интернета с помощью Python (BeautifulSoup)? [закрыто]Python

Программы на Python
Anonymous
Как очистить таблицу из Интернета с помощью Python (BeautifulSoup)? [закрыто]

Сообщение Anonymous »

Я пытаюсь извлечь таблицу с веб-сайта. Я использовал BeautifulSoup, но в конце концов в таблице остались пустые строки, которые я очистил.

Код: Выделить всё

#import package
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup

#to get the html of the page
req = Request('https://covid19.go.id/peta-risiko', headers={'User-Agent': 'Mozilla/5.0'})
html = urlopen(req).read()
soup = BeautifulSoup(html, 'lxml')
type(soup)

# Get the title
title = soup.title
print(title)

# Print out the text
text = soup.get_text()
print(soup.text)

#to extract all the hyperlinks within the webpage
soup.find_all('a')

#use a for loop and the get('"href") method to extract and print out only hyperlinks
all_links = soup.find_all("a")

#To print out table rows only, pass the 'tr' argument in soup.find_all()
for link in all_links:
print(link.get("href"))

# Print the first 10 rows for checking
rows = soup.find_all('tr')
print(rows[:10])
Я получаю [], когда печатаю первые 10 строк. Я не знаю, что это может случиться. Это потому, что таблица состоит из нескольких страниц (страницы 1, 2, 3, следующая страница и т. д.)?
Любые решения для очистки этой таблицы в этой таблице сеть? Веб-страница. Я хочу получить таблицу со столбцами: ПРОВИНСИ, КОТА/КАБУПАТЕН, СТАТУС

Подробнее здесь: https://stackoverflow.com/questions/685 ... utifulsoup

Вернуться в «Python»