Skip to content

Instantly share code, notes, and snippets.

@markuskreitzer
Created February 19, 2014 00:38
Show Gist options
  • Save markuskreitzer/9083782 to your computer and use it in GitHub Desktop.
Save markuskreitzer/9083782 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import urllib2
import urllib
from BeautifulSoup import BeautifulSoup, Comment
from pprint import pprint
url = 'http://www.alicehendersonrealty.com/ajax/'
query = {
'type_of_property': 'Rental',
'min_price': 0,
'max_price': 1500,
'number_of_bedrooms': 2,
'number_of_bathrooms': 1,
'property_city': 'Auburn',
'functionz': 'filter_form'
}
data = urllib.urlencode(query)
#print data
request = urllib2.Request(url)
request.add_header("Accept","Application/XML")
result = urllib2.urlopen(request,data)
t = result.read()
bs = BeautifulSoup(t)
results = []
for row in bs.findAll('tr'):
#print row
results.append( { 'picture_link' : row.findChild().findChild()['src'],
'detail_link' : row.findAll('a')[0]['href'],
'pet_friendly': row.findAll('p')[1].string,
'address' : row.findAll('address')[0].string,
'is_available' : row.findAll('p')[0].string,
'rent_price' : row.findAll('h1')[0].getText()
}
)
#### END for
pprint(results,indent=4)
# Initial Idea came from:
"""curl 'http://www.alicehendersonrealty.com/ajax/' --data 'type_of_property=Rental+All&min_price=0&max_price=1500&number_of_bedrooms=2&number_of_bathrooms=1&property_city=Auburn&functionz=filter_form'
-H 'Cookie: __utma=266093791.1889026828.1392739854.1392739854.1392761320.2; __utmb=266093791.20.10.1392761320; __utmc=266093791; __utmz=266093791.1392761320.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=http%3A%2F%2Fwww.alicehendersonrealty.com%2Frental%2F928-e-glenn%2F'
-H 'Origin: http://www.alicehendersonrealty.com'
-H 'Accept-Encoding: gzip,deflate,sdch'
-H 'Accept-Language: en-US,en;q=0.8,af;q=0.6'
-H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36'
-H 'Content-Type: application/x-www-form-urlencoded'
-H 'Accept: text/html, */*; q=0.01'
-H 'Referer: http://www.alicehendersonrealty.com/rentals/'
-H 'X-Requested-With: XMLHttpRequest'
-H 'Connection: keep-alive'
--compressed"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment