Log-in to forums (using cookielib)?

O

Olivier Oost

Hi,

I need to login to a online forum, like a phpbb forum, and leave a
message there. I figured I need to use cookielib, but the documentation
of cookielib is not very clear to me.

I tried to just copy/paste all the cookies from FireFox into my
Python-program, like this:
import cookielib, urllib2, urllib
cookiejar=cookielib.CookieJar()
urlOpener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
values={'__utmb':'1234', 'mybbuser':'1234_1234', '__utmz':'1234',
'sid':'1234', '__utma':'1234'}
data=urllib.urlencode(values)
request=urllib2.Request("http://ep2.nl",data)
url=urlOpener.open(request)
page=url.read(1024000)

Can someone please tell me how I should log-in and leave a message on
the board?
 
G

Gabriel Genellina

I need to login to a online forum, like a phpbb forum, and leave a
message there. I figured I need to use cookielib, but the documentation
of cookielib is not very clear to me.
Can someone please tell me how I should log-in and leave a message on
the board?

Sure. But considering that this smells like an Automatic Spamming Machine,
I hope nobody will.
 
O

Olivier Oost

Gabriel said:
Sure. But considering that this smells like an Automatic Spamming
Machine, I hope nobody will.

--Gabriel Genellina

No, it's not meant as a spamming machine. I only need to post a message
and then (if that's possible) lock the topic (I'm admin on the forum
where I need this). The program first needs to read the topic for
certain words (that's already working), and then reply that those words
aren't welcome.

I hope I made myself clear.
 
G

Gabriel Genellina

No, it's not meant as a spamming machine. I only need to post a message
and then (if that's possible) lock the topic (I'm admin on the forum
where I need this). The program first needs to read the topic for
certain words (that's already working), and then reply that those words
aren't welcome.

I would verify that in the forum code if possible, not remotely.
Anyway, the examples at the end of the cookielib section in the library
reference are what you need: create an OpenerDirector using
urllib2.build_opener, adding a suitable HTTPCookieProcessor handler.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top