반응형
from bs4 import BeautifulSoup
import requests
url = "http://allevents.in/lahore/"
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data)
for link in soup.select( 'html body div.non-overlay.gray-trans-back div.container div.row div.span8 div#eh-1748056798.events-horizontal div.eh-container.row ul.eh-slider li.h-item div.h-meta div.title a[href]'):
print link.get('href')
해결 방법
이 페이지는 클래스와 마크 업을 사용하는 데 가장 친숙하지는 않지만 CSS 선택기가 너무 구체적이어서 여기서 유용하지 않습니다.
upcoming_events_div = soup.select_one('div#events-horizontal')
for link in upcoming_events_div.select('div.title a[href]'):
print link['href']
참조 페이지 https://stackoverflow.com/questions/24801548
반응형
'파이썬' 카테고리의 다른 글
파이썬 How to use Python sets and add strings to it in as a dictionary value (0) | 2020.12.12 |
---|---|
파이썬 Pandas - Compute z-score for all columns (0) | 2020.12.12 |
파이썬 How to rename a file using Python (0) | 2020.12.12 |
파이썬 목록에서 모든 값을 파이썬 적으로 산출하는 방법은 무엇입니까? (0) | 2020.12.12 |
파이썬 Python 인터프리터에 코드 복사 및 붙여 넣기 (0) | 2020.12.12 |
댓글