【发布时间】:2020-12-03 00:53:50
【问题描述】:
我想问一下如何使用 python 库 (beautifulSoup) 从 this website 提取活动费用以进行网络抓取。
但是,该活动的费用与其他物业共享同一级别。我想问是否有任何建议只提取费用。我尝试了find_next、find_next_sibling 和find next_parent,但仍然没有用。下面是价格类所在的原始 html 代码:
<div class="eds-event-card-content__sub eds-text-bm eds-text-color--ui-600 eds-l-mar-top-1 eds-event-card-content__sub--cropped">Free</div>
如果能提供任何帮助,我将不胜感激。
以下是我尝试过的代码。我只在我的数组中得到一个标签列表。
import pandas as pd
import requests
from bs4 import BeautifulSoup
url = 'https://www.eventbrite.com/d/malaysia--kuala-lumpur--85675181/all-events/?page=1'
response = requests.get(url)
soup = BeautifulSoup(response.text, "html.parser")
#Finding common container for each event
containers = soup.find_all('article', class_ = 'eds-l-pad-all-4 eds-event-card-content eds-event-card-content--list eds-event-card-content--standard eds-event-card-content--fixed eds-l-pad-vert-3')
event_fees = []
for container in containers:
fees = soup.select('div', class_ ='eds-event-card-content__sub eds-text-bm eds-text-color--ui-600 eds-l-mar-top-1 eds-event-card-content__sub--cropped')
event_fees.append(fees.txt)
【问题讨论】:
标签: python web beautifulsoup