Wikipedia Bot

I’m planning on writing a simple Wikipedia Bot, but I’m having a little
difficulty. The bot needs to be able to log in to Wikipedia, but I’m not
sure if this code is working. It returns the Main Page, which does
happen after you log in, but I’m not entirely sure if this means if I’ve
actually logged in or not. Here’s what I’ve used (ripped from:
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net/HTTP.html):

require ‘net/http’
require ‘uri’

res =
Net::HTTP.post_form(URI.parse(‘Log in - Wikipedia’,
‘wpPassword’=>‘password_not_this_one’})
puts res.body

My user & password were correct.

Peter M. wrote:

res =
Net::HTTP.post_form(URI.parse(‘Log in - Wikipedia’,
‘wpPassword’=>‘password_not_this_one’})
puts res.body

My user & password were correct.

On the main page, see the text where it says “Sign in / create account”?
Search the body for that text. It won’t say that if the login was
successful.

Dan

Dan Z. wrote:

Peter M. wrote:

res =
Net::HTTP.post_form(URI.parse(‘Log in - Wikipedia’,
‘wpPassword’=>‘password_not_this_one’})
puts res.body

My user & password were correct.

On the main page, see the text where it says “Sign in / create account”?
Search the body for that text. It won’t say that if the login was
successful.

Dan

That’s the thing, I’ve tried that but I can’t find ‘sign in’ ‘sign out’
or the my username, which usually appears in the top right. Also, I’ve
tried looking at the pade via IE after I’ve run the code, and that says
I’m not signed in as well.

Any ideas?

On May 21, 2007, at 10:27 , Peter M. wrote:

I’m planning on writing a simple Wikipedia Bot, but I’m having a
little
difficulty. The bot needs to be able to log in to Wikipedia, but
I’m not
sure if this code is working. It returns the Main Page, which does
happen after you log in, but I’m not entirely sure if this means if
I’ve
actually logged in or not.

Guess I’m going to be the one to ask: why do you need a wikipedia bot?

On Monday 21 May 2007 20:52, Peter M. wrote:

On the main page, see the text where it says “Sign in / create account”?
Any ideas?
I recomend using scrubyt - there was example how to log into site, and
post
comment - i guess it can be easly changed to wiki - but don’t spam
please :smiley:

That’s the thing, I’ve tried that but I can’t find ‘sign in’ ‘sign out’
or the my username, which usually appears in the top right. Also, I’ve
tried looking at the pade via IE after I’ve run the code, and that says
I’m not signed in as well.

Any ideas?

Check if there is a cookie involved that stores your session. As far as
I understand the HTTP protocol, it is possible that WP is sending you a
redirect together with your session cookie, which it expects to be sent
back when (automatically) trying to GET the MainPage.

It is just an idea, I never looked at the login process of WP and
neither fully understand how much of the cookie handling is done for you
with the Net::HTTP module.

Dinkel

On 5/22/07, Christian L. [email protected] wrote:

back when (automatically) trying to GET the MainPage.

It is just an idea, I never looked at the login process of WP and
neither fully understand how much of the cookie handling is done for you
with the Net::HTTP module.

I’m pretty sure that mediawiki (the software behind wikipedia) does in
fact use a cookie for authorization. It’s been a while since I looked
at the code.

The OP might want to have a look at the pywikipediabot framework and
see how they do it. This is the ‘official’ bot framework for
wikipedia. It’s written in python as the name would indicate, but
python code isn’t THAT hard to read.

It would be cool if there were a ruby equivalent to pywikipedia.

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

Ryan D. wrote:

On May 21, 2007, at 10:27 , Peter M. wrote:

I’m planning on writing a simple Wikipedia Bot, but I’m having a
little
difficulty. The bot needs to be able to log in to Wikipedia, but
I’m not
sure if this code is working. It returns the Main Page, which does
happen after you log in, but I’m not entirely sure if this means if
I’ve
actually logged in or not.

Guess I’m going to be the one to ask: why do you need a wikipedia bot?

I don’t need one at all personally, but there are loads of requests for
bots of all sorts from the community. I thought that it’d be a nice
project to start, and would actually be useful! I’m not upto no good :stuck_out_tongue:

Pywikipedia looks pretty promising - since I’m learning Ruby I may as
well learn Python!

Rick DeNatale wrote:

It would be cool if there were a ruby equivalent to pywikipedia.

We have written what you’re looking for, but a year ago and we’ve not
taken care of it since then. But it should be still working with recent
MediaWikis.

Be aware that most documentation is in german but the code itself is
english.

Homepage:
Ruby-MediaWiki – C3D2

Automatic RDoc in a Wiki:
Ruby-MediaWiki/Documentation – C3D2

Repository:
svn://svn.c3d2.de/ruby-mediawiki/trunk

Source browser:
http://trac.c3d2.de/ruby-mediawiki/browser/trunk/

Stephan

Stephan M. wrote:

Stephan M. wrote:

Be aware that most documentation is in german but the code itself is
english.

Err. Actually only the homepage is german, the RDoc is english.

Excellent, I’ll have a look!

Stephan M. wrote:

Be aware that most documentation is in german but the code itself is
english.

Err. Actually only the homepage is german, the RDoc is english.

On 5/22/07, Stephan M. [email protected] wrote:

Rick DeNatale wrote:

It would be cool if there were a ruby equivalent to pywikipedia.

We have written what you’re looking for, but a year ago and we’ve not
taken care of it since then.

Cool, if I once again need it I’ll take a look.

But it should be still working with recent
MediaWikis.

There’s the rub*, when I was using the pywikipediabot the team had a
time keeping up with the evolution of mediawiki. It’s a problem with
screen-scraping, you need to keep up the the screen you’re scraping.

*pre-s: It’s happening to me again. For years I had the tendency to
type smalltalk automatically whenever I typed small. In fact it
lingers on sporadically even today. Just now I typed: There’s the
ruby

Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

*pre-s: It’s happening to me again. For years I had the tendency to
type smalltalk automatically whenever I typed small. In fact it
lingers on sporadically even today. Just now I typed: There’s the
ruby

I get that now and then, but quite often I can’t track down where it’s
come from. Weird.

[email protected] wrote:

*pre-s: It’s happening to me again. For years I had the tendency to
type smalltalk automatically whenever I typed small. In fact it
lingers on sporadically even today. Just now I typed: There’s the
ruby

I get that now and then, but quite often I can’t track down where it’s
come from. Weird.

for a time, I couldn’t type “myself” without first typing “mysql”. Way
too much php scripting that summer.

Kristoffer Lundén wrote:

On 5/22/07, Peter M. [email protected] wrote:

Pywikipedia looks pretty promising - since I’m learning Ruby I may as
well learn Python!

Last I looked at Pywikipedia the design was horribly broken - don’t
recall details exactly, but it was really really painful to try and
extend or enhance it in any way. Putting up a simple Ruby-bot that did
a better job was a matter of hours. Using some of the high-level HTTP
automation libs that exist it should be even faster, and very
maintainable if you put some thought into it.

Duplicating effort is the right way to go at times. :slight_smile:

– K

Well, from what I’ve seen so far it doesn’t actually seem that bad -
however I’m really new to Pywikipedia/Ruby/Python so you probally know
better than me :). The biggest pain in the arse at the moment is
actually getting permission to run a bot!

On 5/22/07, Peter M. [email protected] wrote:

Pywikipedia looks pretty promising - since I’m learning Ruby I may as
well learn Python!

Last I looked at Pywikipedia the design was horribly broken - don’t
recall details exactly, but it was really really painful to try and
extend or enhance it in any way. Putting up a simple Ruby-bot that did
a better job was a matter of hours. Using some of the high-level HTTP
automation libs that exist it should be even faster, and very
maintainable if you put some thought into it.

Duplicating effort is the right way to go at times. :slight_smile:

– K

On 5/25/07, Peter M. [email protected] wrote:

Well, from what I’ve seen so far it doesn’t actually seem that bad -
however I’m really new to Pywikipedia/Ruby/Python so you probally know
better than me :). The biggest pain in the arse at the moment is
actually getting permission to run a bot!

If you just want to do what it already does, such as helping with
cross-language referencing, it’s probably fine. It’s when you want to
do something new, or something more advanced it gets really tricky.

– K