Skip to content

Instantly share code, notes, and snippets.

@mouseroot
Created October 3, 2013 21:49
Show Gist options
  • Select an option

  • Save mouseroot/6817660 to your computer and use it in GitHub Desktop.

Select an option

Save mouseroot/6817660 to your computer and use it in GitHub Desktop.
Beautiful soup test
#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