Tag: urllib.request

Learning Python – make a URL request

rosetwoandbuds002  Been learning Python lately.  Have done a couple of tutorials and one or two simple programs.  This post will be about a simple example of how to access some real estate information that is available from a company called Trulia.

First, some links to sites that helped me figure this out:

  • Download Python, install, and some reference documentation: https://www.python.org/downloads/
  • Stackoverflow thread about making a URL request in Python: http://stackoverflow.com/questions/17301938/making-a-request-to-a-restful-api-using-python
  • How to make a Trulia RSS feed with your real estate search criteria: https://www.trulia.com/tools/rss/#code_block
  • Some free python IDEs: http://insights.dice.com/2014/09/23/look-5-free-python-editors/
  • I decided to go with Visual Studio for an IDE. I picked the custom installation so I could specify Python as a supported language.  https://www.visualstudio.com/downloads/

The code:

#Just a little POC to retrieve some real estate information from the web
#Python 3
 
import urllib.request #for opening connections to URLs

def main():

  truliaURL = 'https://www.trulia.com/rss2/for_sale/Burbank,CA/'

  request = urllib.request.Request(truliaURL)
  response = urllib.request.urlopen(request)
  responseData = response.read().decode('utf-8')
  print(responseData)

if __name__ == "__main__":
 main()
Advertisements