|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
|
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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/. > > |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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/. |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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/. > > |
|
![]() |
| Outils de la discussion | |
|
|