I'm trying to learn beatifulsoup (and python as a whole, pretty much still a beginner) and playing around with how to use it properly. I notice that when I scrape the website I'm testing for data from the search results, it lists it 3 times.
Specifically, I'm trying to output the title, link, and price of the real estate property from the website. The price doesn't seem to duplicate while the title and link does. Can't really figure out if it's because of my code or something with the website itself.
import requests
from bs4 import BeautifulSoup
userSearch = input('Input search: ')
link = 'https://www.lamudi.com.ph/buy/?q={}'.format(userSearch)
page = requests.get(link)
soup = BeautifulSoup(page.content, 'html.parser')
titleList = soup.find_all("a", title=True)
priceList = soup.find_all("span", class_="PriceSection-FirstPrice", text=True)
for (i,j) in zip(titleList, priceList):
print(i['title'])
print(i['href'])
print(j.get_text())
print("===============")
Output would be something like this where the price doesn't match the listing because of the duplicated info:
Input Property search: manila
Suntrust Solana in Ermita Manila 3 Bedroom Unit for Sale
https://www.lamudi.com.ph/suntrust-solana-in-ermita-manila-3-bedroom-unit-for-sale.html
₱ 6,672,197
===============
Suntrust Solana in Ermita Manila 3 Bedroom Unit for Sale
https://www.lamudi.com.ph/suntrust-solana-in-ermita-manila-3-bedroom-unit-for-sale.html
₱ 6,888,800
===============
Suntrust Solana in Ermita Manila 3 Bedroom Unit for Sale
https://www.lamudi.com.ph/suntrust-solana-in-ermita-manila-3-bedroom-unit-for-sale.html
₱ 168,000,000
===============
3 Bedroom Unit For Sale in Suntrust Solana Manila- SOLA-01-21-H
https://www.lamudi.com.ph/3-bedroom-unit-for-sale-in-suntrust-solana-manila-sola-01-21-h.html
₱ 53,000,000
===============
3 Bedroom Unit For Sale in Suntrust Solana Manila- SOLA-01-21-H
https://www.lamudi.com.ph/3-bedroom-unit-for-sale-in-suntrust-solana-manila-sola-01-21-h.html
₱ 53,000,000
===============
3 Bedroom Unit For Sale in Suntrust Solana Manila- SOLA-01-21-H
https://www.lamudi.com.ph/3-bedroom-unit-for-sale-in-suntrust-solana-manila-sola-01-21-h.html
₱ 46,500,000