웹 사이트에서 가격을 추출하려고합니다.
내가 작성한 코드는 그렇게 할 수 있지만 웹 사이트에 이전 가격도 표시되는 가격이있는 경우 가격 문자열 대신 "none"을 반환합니다.
이것은 이전 가격이없는 코드의 예입니다 (내 코드는 문자열로 반환 됨).
<div class="xl-price rangePrice">
535.000 €
</div>
이것은 이전 가격이있는 코드의 예입니다 (내 코드는 "없음"으로 반환 됨).
< div
class ="xl-price rangePrice" >
487.000 €
< span
class ="old-price" > 497.000 € < br > < / span >
< / div >
코드를 추출하려는 페이지 : pagelink
내 코드 :
prices = []
for items in soup.find_all("div", {"class": "xl-price rangePrice"}):
prices.append(items.string)
print(prices)
또 다른 문제는 다음과 같은 값을 반환한다는 것입니다.
'\r\n\t\t\t\t\t\t\t\t298.000 € \r\n\t\t\t\t\t\t\t', '\r\n\t\t\t\t\t\t\t\t145.000 € \r\n\t\t\t\t\t\t\t'
숫자 만 원할 때.
도움을 주시면 감사하겠습니다!
import requests
from bs4 import BeautifulSoup
r = requests.get(
'https://www.immoweb.be/en/search/apartment/for-sale/leuven/3000')
soup = BeautifulSoup(r.text, 'html.parser')
for item in soup.findAll('div', attrs={'class': 'xl-price rangePrice'}):
item = item.contents[0]
print(item.strip()[0:-1])
산출:
298.000
145.000
275.000
535.000
487.000
159.000
325.000
189.000
139.000
499.000
520.000
249.500
448.000
215.000
225.000
210.000
215.000
218.000
232.000
689.000
228.000
299.500
169.000
135.000
549.000
125.000
160.000
395.000
430.000
210.000
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다