tamouse m. wrote in post #1122204:
When I try to get the page with hpricot
doc = Hpricot(open(@link))
I always have a 404 error, but if I print the @link variable to the view
I can access the URL just fine. So I guess its the way im trying to open
it with hpricot that is wrong.
From what I can see, you are sending page.link back to the client in
index.erb. can you show the content that is sent back? (html source,
please)
Im sorry but I think I dont undestood.
The page.link is working fine, the html on the index.erb is just a bunch
of links to the profiles.
That's what *I* said.
Use nokogiri instead. It's more correct in nearly every way.
I tried this:
def initialize(link)
site = "https://www.facebook.com/"
@link = site + link
page = Nokogiri::HTML(open(site + link))
@title = page.css("title").text
Try this, just for me. Change the above two lines to this:
html_doc = Nokogiri::HTML(open(@link))
@title = html_doc.css("title").text
(Note you could put those on one line, like so:
@title = Nokigiri::HTML(open(@link)).css("title").text
)
Two things:
1) the variable page might be used elsewhere. making it unique here might help.
2) using the variable you just set, and will be using in the ERB, makes sure it is the same in the open.
end
And it still returns a 404 error "OpenURI::HTTPError at / 404 Not
Found".
Its strange because im using the same address to create the page.link
and it works!
Do this for me as well, from the command line, take one of those page.links from your output, and fetch it with either curl or wget.
This is because I have known of sites (not sure if FB is like this or not) that respond differently depending on specific contents of the request header, which can be different between open-uri, curl, wget and various browsers.
···
On Sep 24, 2013, at 7:25 AM, Mario Me <lists@ruby-forum.com> wrote:
On Sep 23, 2013, at 3:41 PM, Mario Me <lists@ruby-forum.com> wrote: