[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Wikipedia Bot

Peter Marsh

5/21/2007 5:27:00 PM

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...):


require 'net/http'
require 'uri'

res =
Net::HTTP.post_form(URI.parse('http://en.wikipedia.org/w/index.php?title=Special:Userlogin&returnto=Main...),{'wpName'=>'username_not_this_one',
'wpPassword'=>'password_not_this_one'})
puts res.body

My user & password were correct.

--
Posted via http://www.ruby-....

22 Answers

Dan Zwell

5/21/2007 5:54:00 PM

0

Peter Marsh 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. Here's what I've used (ripped from:
> http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/classes/Net...):
>
>
> require 'net/http'
> require 'uri'
>
> res =
> Net::HTTP.post_form(URI.parse('http://en.wikipedia.org/w/index.php?title=Special:Userlogin&returnto=Main...),{'wpName'=>'username_not_this_one',
> '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

Peter Marsh

5/21/2007 8:52:00 PM

0

Dan Zwell wrote:
> Peter Marsh wrote:
>>
>> res =
>> Net::HTTP.post_form(URI.parse('http://en.wikipedia.org/w/index.php?title=Special:Userlogin&returnto=Main...),{'wpName'=>'username_not_this_one',
>> '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?

--
Posted via http://www.ruby-....

Marcin Raczkowski

5/21/2007 9:41:00 PM

0

On Monday 21 May 2007 20:52, Peter Marsh wrote:
> Dan Zwell wrote:
> > Peter Marsh wrote:
> >> res =
> >> Net::HTTP.post_form(URI.parse('http://en.wikipedia.org/w/index...
> >>=Special:Userlogin&returnto=Main_Page'),{'wpName'=>'username_not_this_one
> >>', '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?

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 :D

--
Marcin Raczkowski
---
Friends teach what you should know
Enemies Teach what you have to know

Ryan Davis

5/21/2007 11:58:00 PM

0


On May 21, 2007, at 10:27 , Peter Marsh 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?



Christian Luginbuehl

5/22/2007 2:09:00 PM

0

> 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

Rick DeNatale

5/22/2007 2:56:00 PM

0

On 5/22/07, Christian Luginbuehl <dinkel@pimprecords.com> wrote:
> > 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.

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. <G>

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

My blog on Ruby
http://talklikeaduck.denh...

Peter Marsh

5/22/2007 3:22:00 PM

0

Ryan Davis wrote:
> On May 21, 2007, at 10:27 , Peter Marsh 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 :P

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

--
Posted via http://www.ruby-....

Stephan Maka

5/22/2007 3:27:00 PM

0

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:
https://wiki.c3d2.de/Ruby...

Automatic RDoc in a Wiki:
https://wiki.c3d2.de/Ruby.../Documentation

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

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


Stephan

Stephan Maka

5/22/2007 3:32:00 PM

0

Stephan Maka 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.

Peter Marsh

5/22/2007 4:03:00 PM

0

Stephan Maka wrote:
> Stephan Maka 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!

--
Posted via http://www.ruby-....