Member Avatar for sravan953

Hey,

I am thinking of making a Facebook application, where you open the app, enter your login details, and it passes the data and logs into the acc, and gets the HTML code, writes it to a .html file and opens it....I don't know how to make it pass the data using the urllib/urllib2 module....so any ideas on how I can solve this prob?

import urllib
import urllib2

url = 'http://www.someserver.com/login.php'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
values = {'username' : 'write username',
          'pass' : 'write pass'}
headers = { 'User-Agent' : user_agent }

data = urllib.urlencode(values)
req = urllib2.Request(url, data, headers)
response = urllib2.urlopen(req)
get_page = response.read()
#And finally you can write to HTML file
file=open("page.html", 'w')
file.write(get_page)
file.close()

You can process a page via given post values with PHP etc. but if you want to use it specificly with facebook.com you must browse for the HTML code of facebook login page to determine form value names which will be sent.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.