| Top | Previous | Next |
|
system.net.httpGet |
|
Description Retrieves the document at the given URL using the HTTP GET protocol. The document is returned as a string. For example, if you use the URL of a website, you'll get the same thing you'd get by going to that website in a browser and using the browser's "View Source" function. Syntax system.net.httpGet(url) Parameters String url - The URL to retrieve. Returns String - The content found at the given URL. Scope All Examples Example 1:
# This code would return the source for Google's homepage source = system.net.httpGet("http://www.google.com") print source
Example 2:
# This code would query Yahoo Weather for the temperature in Sacramento, CA # and then find the current temperature using a regular expression
response = system.net.httpGet("http://xml.weather.yahoo.com/forecastrss?p=95818")
# import Python's regular expression library import re
# NOTE - if you've never seen regular expressions before, don't worry, they look # confusing even to people who use them frequently. pattern = re.compile('.*?<yweather:condition (.*?)/>', re.DOTALL) match = pattern.match(response) if match: subText = match.group(1) condition = re.compile('.*?text="(.*?)"').match(subText).group(1) temp = re.compile('.*?temp="(.*?)"').match(subText).group(1) print "Condition: ", condition print "Temperature (F): ", temp else: print 'Weather service format changed'
|