[Tutor] urllib2 & form submit
Ed Hotchkiss
edhotchkiss at gmail.com
Wed Oct 26 19:44:10 CEST 2005
i am trying to write a class to log into myspace. either i am doing
something wrong, or... myspace is requiring that i accept a cookie, or
create a session? however i am new to urllib and urllib2.
heres my code:
correctly formatted code is at: http://www.jeah.net/~marla/myspace.py
#!/bin/env python
# -----------
import sgmllib
import urllib
import urllib2
import urlparse
# -----------
class myspace:
# login to one myspace account
def login(self, user, password):
the_url = "
http://viewmorepics.myspace.com/index.cfm?fuseaction=login.process"
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
headers = { 'User-Agent' : user_agent }
values = { 'email' : user,
'password' : password }
data = urllib.urlencode(values)
req = urllib2.Request(the_url, data)
try:
handle = urllib2.urlopen(req)
except IOError:
print 'Something went wrong'
else:
x = handle.read()
temp = open("edspage.html", "w")
temp.write(x)
temp.close()
# add friend based on users URL
def addFriend(self, friendURL):
return 1
# delete friend based on users URL
def deleteFriend(self, friendURL):
return 1
# post a friends bulletin
def postBulletin(self, bulletin):
return 1
# read all bulletins into a tuple named 'bulletins'
def readBulletins(self):
bulletins = {}
# a photo to your profile
def addPhoto(self, photoLocation):
return 1
# delete a photo from your profile
def deletePhoto(self, photoID):
return 1
# return a tuple of people that match your browsing criteria
def browse(self, sex, ageBegin, ageEnd, gayBiStraight, zipCode, zipRange):
return 1
# stick someones myspace page into an html file
def grabUserPageHTML(self, xURL, outputFile):
req = urllib2.Request(xURL)
handle = urllib2.urlopen(req)
thepage = handle.read()
temp = open(outputFile, "w")
temp.write(thepage)
temp.close()
def logout(self):
return 1
# -----------
# example of class usage
me = myspace()
me.login("xxx at gmail.com", "password here")
#me.grabUserPageHTML("http://www.myspace.com/blahuser/","blah.html")
#me.logout()
# -----------
EOF
the form uses POST method. the action for the form is the_url. what am i
doing wrong? all that the script does, is to refer me to another login page.
is it detecting somehow that i am a script and not a users browser? any help
would be appreciate, lost in the water here.
--
edward hotchkiss
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20051026/0166ff2c/attachment.htm
More information about the Tutor
mailing list