event_containers
이 Tag
개체의 목록은 기본적으로 인하는 bs4.element.ResultSet
객체입니다 readmore 링크를 클릭 한 후 뚜렷한 인 위치 정보를 추출하기 위해 노력하고있어.
단지의 event_containers
의 태그를 통해 루프와 URL, 예를 들어 날짜의 제목에 대한 h3
, div.date
및 a
를 선택
for tag in event_containers:
print(tag.h3.text)
print(tag.select_one('div.date').text)
print(tag.a['href'])
지금은 위치 정보를 각 URL을 방문해야하고 div.date
에 텍스트를 수집하십시오.
전체 코드 :
import requests
from bs4 import BeautifulSoup
res = requests.get('http://aicd.companydirectors.com.au/events/events-calendar')
soup = BeautifulSoup(res.text,"lxml")
event_containers = soup.find_all('div', class_ = "col-xs-12 col-sm-6 col-md-8")
base_url = 'http://aicd.companydirectors.com.au'
for tag in event_containers:
link = base_url + tag.a['href']
soup = BeautifulSoup(requests.get(link).text,"lxml")
location = ', '.join(list(soup.select_one('div.event-add').stripped_strings)[1:-1])
print('Title:', tag.h3.text)
print('Date:', tag.select_one('div.date').text)
print('Link:', link)
print('Location:', location)
'''movie_containers에서 영화 :''' – Martin
은 그냥 들어, 이것을 시도 할 것이다 FYI 나는 방금 영화를 이벤트로 바꿨으므로 더 이해할 수 있습니다. – Mahesh