python - 使用 beautifulsoup 从 Eventbrite 抓取数据
问题描述
我正在探索和理解python中的beautiful-soup,所以我决定尝试网络抓取Eventbrite的事件数据。我想知道为什么我的刮板功能没有接受页面中列出的任何事件。由于某种原因,数据框为空。是不是因为我叫错了班级?我知道该网站有一个 API,但我想在使用 API 之前先尝试网页抓取。
到目前为止,这是我的代码
import requests
from bs4 import BeautifulSoup
import pandas as pd
event = []
location = []
price = []
date = []
eventbrite_url = "https://www.eventbrite.com/d/ca--san-diego/art-events/"
try:
page = requests.get(kpbs_url)
soup = BeautifulSoup(page.text, 'html.parser')
items = soup.find_all("li", {"class": "item"})
for item in items:
event.append(item.find('div', {"class": "eds-is-hidden-accessible"}).text.strip())
location.append(item.find('div', {"class": "card-text--truncated__one"}).text.strip())
date.append(item.find('div', {"class":"eds-text-color--primary-brand eds-l-pad-bot-1 eds-text-weight--heavy eds-text-bs"}).text.strip())
try:
price.append(item.find('div', {"class": "eds-media-card-content__sub eds-text-bm eds-text-color--grey-600 eds-1-mar-top-1 eds-media-card-content__sub--cropped"}).text.strip())
except:
price.append('Free')
final_df = pd.DataFrame(
{'Event': event,
'Location': location,
'Price': price,
'Date':date
})
except Exception as e:
print(e)
print("continuing....")
解决方案
推荐阅读
- google-apps-script - 如何从 Binance API 获取 Binance 的 BTC 价格
- java - 使用 RestHighLevelClient 执行弹性搜索查询的最佳方法是什么
- spring-boot - 使用 Spring Boot 和 thymeleaf 重定向
- python - python根据多数更改字典的值
- solr - Solr [8.8] 重启后将所有集合移动到一个节点
- http - 如何发送带有 URL 参数和 JSON 正文的 POST?
- angular - 如何通过角度形式验证图像尺寸或是否可以验证使用角度形式?
- java - 它是如何决定 Predicate “and” 方法在 java 中有一个消费者而不是生产者的?
- javascript - 引导选择通过值禁用
- kotlin - 在 Kotlin 中创建子协程范围