Reputation: 1
I'm trying to scrape data from "http://www.landwatch.com/Philippines_land_for_sale/Land"; what I need are the address and price info. My methodology is using the beautiful soup module in python. I got stuck when I inspected the html page, also with coding. May some of you give me a bit hint so I can move on. Basically the web inspection indicated that the information I need is from div class = clear property left, and here are the code:
from lxml import html
import requests
import bs4 as bs
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'http://www.landwatch.com/Philippines_land_for_sale/Land'
#Openning up connection, grabbing the page
uClient = uReq(my_url)
page_html = uClient.read()
soup = bs.BeautifulSoup(page_html,'lxml')
g_data = soup.find_all("div",{"class": "clear property left"})
for item in g_data:
print(item).contents[0]
thanks,
Upvotes: 0
Views: 192
Reputation: 6556
You are almost there, the address and price info is in the <a>
element of <div class="propName">
under <div class="clear property left">
, you can find deeper inside the g_data
, like this:
import requests
from bs4 import BeautifulSoup
my_url = 'http://www.landwatch.com/Philippines_land_for_sale/Land'
link=requests.get(my_url)
soup = BeautifulSoup(link.content, 'lxml')
g_data =soup.find_all('div',class_='clear property left')
for item in g_data:
address_price_info = item.find("div",{"class":"propName"}).find('a').text
print(address_price_info )
Output will be:
Cebu City, Philippines 1185000, PHP
Tagaytay, Philippines $116,000
Quezon City, Philippines $2,837,000
Sta Rosa Laguna, Philippines 15500, PHP
Makati, Philippines $5,947,826
Puerto Princesa City, Philippines $358,813
Carcar, Philippines 35000000, PHP
Lipa City, Philippines $57,750
Makati, Philippines 6400000, PHP
Taytay, Philippines $2,300,000
Taguig, Philippines $504,208
Taguig City, Philippines $13,760
Quezon City, Philippines 58000000, PHP
Cebu City, Philippines 7799030, PHP
Las Pinas, Philippines $468,000
Update:
If you use chrome to inspect the address and price info, it will show you the location:
<div class="clear property left">
<div class="margintop">
...
<div class="propName"> #Here is the address and price info
<a href="/Cebu-City-Philippines-Land-for-sale/pid/119211639" onclick="WC('119211639', '-1');"> Cebu City, Philippines <BR/> 1185000, PHP</a>
</div>
<div>PAYMENT SCHEMES:\r\rReservation Fee : P20,000 (non refundable)\r\r1. SCHEME 1\rCash - 100% with the following discounts\r* 10% for 7 days payment\r* 8%... </div>
...
</div>
<div class="clear"></div>
</div>
Upvotes: 2