PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > Faking the refering page with Mechanize
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Faking the refering page with Mechanize

Réponse
 
LinkBack Outils de la discussion
Vieux 06/11/2007, 00h01   #1
ehudros@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Faking the refering page with Mechanize

Hi,
I am trying to access a certain web page from my server, but I want the
referring page to be a different one.
It seems the the get method accepts both a url and a "ref" parameter
that is is supposed to be the referring page, but when I try to send
that url as follows:
agent.get(url_to_get, "http://www.mininova.org")
I get the following error:
ndefined method `uri' for "http://www.mininova.org":String.

Anyone knows what is the correct way to do this?

Thanks!
Ehud
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 06/11/2007, 00h24   #2
ehudros@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

Konrad Meyer wrote:
> Quoth Ehud Rosenberg:
>> Anyone knows what is the correct way to do this?
>>
>> Thanks!
>> Ehud

>
> What you need to do is create a Mechanize::URI object (or something like
> that)
> from the string "http://www.mininova.org", and call #get() with that.
>
> HTH,


Hi Konrad,
Thanks for the quick reply
I managed to get around that error by doing the following:
ref = WWW::Mechanize::Page.new(URI.parse("http://www.mininova.org"),
{'content-type'=>'text/html'})
doc = agent.get(url_to_get, ref)

Problem is, when I sniff the package it seems that the referring url is
ignored and it is still set to localhost:3000. I've also tried
specifying a nil page (as I've seen in the mechanize get code itself)
but to no avail...

Any would be appreciated.
BTW - removing the referrer altogether would also work for, albeit it's
a less preferred option.

Thanks!

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

  Réponse avec citation
Vieux 07/11/2007, 13h37   #3
Ehud Rosenberg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

Anyone? I'm really stumped here
Thanks...
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 07/11/2007, 14h35   #4
Cédric Finance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I tried it and it seems that the header is correct.

require 'mechanize'
require 'logger'
logger = Logger.new $stdout
agent = WWW::Mechanize.new
agent.log = logger
ref = WWW::Mechanize::Page.new("http://www.mininova.org',{ 'content-type' =>
'text/html' })
agent.get url, ref

output from logger ==>
I, [2007-11-07T14:34:06.401219 #23290] INFO -- : Net::HTTP::Get: /
D, [2007-11-07T14:34:06.401585 #23290] DEBUG -- : request-header:
accept-languag
e => en-us,en;q0.5
D, [2007-11-07T14:34:06.401664 #23290] DEBUG -- : request-header: accept =>
*/*
D, [2007-11-07T14:34:06.401733 #23290] DEBUG -- : request-header:
accept-encoding => gzip,identity
D, [2007-11-07T14:34:06.401801 #23290] DEBUG -- : request-header: user-agent
=> WWW-Mechanize/0.6.5 (http://rubyforge.org/projects/mechanize/)
D, [2007-11-07T14:34:06.401869 #23290] DEBUG -- : request-header: referer =>
http://www.mininova.org


On Nov 7, 2007 2:37 PM, Ehud Rosenberg <ehudros@gmail.com> wrote:

> Anyone? I'm really stumped here
> Thanks...
> --
> Posted via http://www.ruby-forum.com/.
>
>


  Réponse avec citation
Vieux 07/11/2007, 17h22   #5
Ehud Rosenberg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

Wow, that's strange.
Thanks for taking the time to check this, I'll try and run it again to
see if I can figure out what im doing wrong.

Thanks
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 08/11/2007, 16h44   #6
Ehud Rosenberg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

In the following line:
ref =
WWW::Mechanize::Page.new("http://www.mininova.org',{'content-type'=>'text/html'
})
the second apostrophe after mininova.org does not match the first one ("
vs. ').

When I try to run it with both sides contained by a double quote, i get
a message saying:
NoMethodError: undefined method `path' for
"http://www.mininova.org":String

That's why I used the URI.parse method before.
this is really strange, are you sure that's the exact syntax you used?

Thanks!
Ehud
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 08/11/2007, 18h23   #7
Ehud Rosenberg
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

OK, I'm stupid
I don't need mechanize to fake the referring page at all, but rails
itself in a redirect_to statement.
The flow is as such:
a. mechanize retrieves a page and scrapes it for a url
b. a redirect_to to that url is sent back to the cient
c. he goes and fetches the url (only right now he gets redirected since
his referrer is wrong.

I am trying to do the following to set the referrer:
request.env['HTTP_REFERER'] = 'http://www.something.com
redirect_to "www.site.com"

but when I sniff the headers, it's still set to my own site...

Any ideas?
Thanks!
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Vieux 08/11/2007, 18h26   #8
Cédric Finance
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Faking the refering page with Mechanize

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

#irb
irb(main):001:0> require 'mechanize'
=> true
irb(main):002:0> require 'logger'
=> true
irb(main):003:0> logger = Logger.new $stdout ; ""
=> ""
irb(main):004:0> agent = WWW::Mechanize.new ; ""
=> ""
irb(main):005:0> agent.log = logger ; ""
=> ""
irb(main):006:0> ref = WWW::Mechanize:: Page.new("http://www.mininova.org",{
'co
ntent-type' => 'text/html' }) ; ""
=> ""
irb(main):007:0> agent.get "http://google.com", ref ; ""
I, [2007-11-08T19:25:06.144484 #21091] INFO -- : Net::HTTP::Get: /
D, [2007-11-08T19:25:06.144937 #21091] DEBUG -- : request-header:
accept-language => en-us,en;q0.5
D, [2007-11-08T19:25:06.145032 #21091] DEBUG -- : request-header: accept =>
*/*
D, [2007-11-08T19:25:06.145106 #21091] DEBUG -- : request-header:
accept-encoding => gzip,identity
D, [2007-11-08T19:25:06.145178 #21091] DEBUG -- : request-header: user-agent
=> WWW-Mechanize/0.6.5 (http://rubyforge.org/projects/mechanize/)
D, [2007-11-08T19:25:06.145253 #21091] DEBUG -- : request-header: referer =>
http://www.mininova.org


Which version of mechanize do you use?

On Nov 8, 2007 5:44 PM, Ehud Rosenberg <ehudros@gmail.com> wrote:

> In the following line:
> ref =
> WWW::Mechanize::Page.new("http://www.mininova.org',{'content-type'=<http://www.mininova.org%27,%7B%27content-type%27=>
> >'text/html'

> })
> the second apostrophe after mininova.org does not match the first one ("
> vs. ').
>
> When I try to run it with both sides contained by a double quote, i get
> a message saying:
> NoMethodError: undefined method `path' for
> "http://www.mininova.org":String
>
> That's why I used the URI.parse method before.
> this is really strange, are you sure that's the exact syntax you used?
>
> Thanks!
> Ehud
> --
> Posted via http://www.ruby-forum.com/.
>
>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h57.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18990 seconds with 16 queries