Created
October 3, 2013 21:49
-
-
Save mouseroot/6817660 to your computer and use it in GitHub Desktop.
Beautiful soup test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #BeautifulSoup Test | |
| from BeautifulSoup import BeautifulSoup | |
| import urllib | |
| import urllib2 | |
| def main(): | |
| #Setup Headers | |
| user_agent = "Mozilla/6 (Windows 7 64bit) Gecko" | |
| headers = {"user-agent" : user_agent} | |
| #Input data | |
| input_values = {"field_name":"field_value"} | |
| encoded_data = urllib.urlencode(input_values) | |
| #Request/Response | |
| #request = urllib2.Request("http://code-dogs.com",encoded_data,headers) | |
| request = urllib2.Request("http://code-dogs.com",None,headers) | |
| response = urllib2.urlopen(request) | |
| page = response.read() | |
| #Beautiful Soup | |
| pool = BeautifulSoup(page) | |
| images = pool.findAll("img",attrs={"class":"entry-image"}) | |
| for image in images: | |
| print image["src"] | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment