【发布时间】:2021-09-10 22:24:56
【问题描述】:
import requests
from bs4 import BeautifulSoup
import pandas as pd
url = "https://ntr.tourism.government.bg/CategoryzationAll.nsf/mn.xsp"
page = requests.get(url)
soup = BeautifulSoup(page.text,'lxml')
print(soup)
data = []
table = soup.find('table', {'class':'table table-striped table-hover mnastaniavane dataTable no-footer'})
table_body = table.find('tbody')
rows = table_body.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [ele.text.strip() for ele in cols]
data.append([ele for ele in cols if ele])
这是网页:https://ntr.tourism.government.bg/CategoryzationAll.nsf/mn.xsp 我想为某个特定位置的大学项目搜索所有酒店(例如瓦尔纳 - 该位置使用西里尔语)。我找到了源代码并描述了确切的表格 - 但我无法从其中刮取任何行/元素等。 请问有什么推荐吗!? 虽然目前有很多信息我没有找到有用的代码来刮表
【问题讨论】:
标签: python web-scraping html-table scrape