【发布时间】:2022-01-18 05:03:21
【问题描述】:
我想爬取这个网站http://www.truellikon.ch/freizeit-kultur/anlaesse-agenda.html。 我想提取每个事件的日期和时间。 您可以看到该日期列在事件上方。为了提取日期和时间,我需要组合不同的 div,但问题是我没有用于同一日期的一组事件的“容器”。 所以我唯一能做的就是提取两个引用日期的 div 之间的所有事件。
这是提取事件信息的代码:
from bs4 import BeautifulSoup
import requests
domain = 'truellikon.ch'
url = 'http://www.truellikon.ch/freizeit-kultur/anlaesse-agenda.html'
def get_website_news_links_truellikonCh():
response = requests.get(url, allow_redirects=True)
print("Response for", url, response)
soup = BeautifulSoup(response.content, 'html.parser')
all_events = soup.select('div.eventItem')
for i in all_events:
print(i)
print()
input()
x = get_website_news_links_truellikonCh()
日期的类名是'listThumbnailMonthName'
我的问题是如何组合这些 div,如何编写选择器以便获得每个事件的确切日期和时间、标题和正文
【问题讨论】:
标签: python web-scraping beautifulsoup