From: 7stud -- Date: 2008-02-04T08:42:26+09:00 Subject: Re: mechanize get methods returns both ::File and ::Page Carl Bernardi wrote: > Hi, > > I am having some problems with WWW::Mechanize. When I use the get(url) > method it unpredictably returns either WWW::Mechanize::File or > WWW::Mechanize::Page. > Since it's a HTML page that I am downloading, I > need to always need it to return a page and not a file for what I am > doing. The content type for this page is "text/plain" which I think is > part of the problem which might have something to do with it. > >>Class WWW::Mechanize::Page >>Synopsis >>This class encapsulates an HTML page. If Mechanize finds a content type of ‘text/html’, this class >>will be instantiated and returned. >> Presumably that means if the content type is not text/*html*, then a Page will not be returned. That makes sense since the synopsis says that a Page encapsulates an *HTML* page. >>WWW::Mechanize::File >>If Mechanize cannot find an appropriate class to use for the content type, this class will be used. For >>example, if you download a JPG, Mechanize will not know how to parse it, so this class will be >>instantiated. >> Since Mechanize is used to parse forms and html, that makes sense: if you don't have an html page(i.e. one with a Content-Type = text/*html*), then you can't parse it as html. >The content type for this page is "text/plain" which I think is >part of the problem which might have something to do with it. A page with a content type of 'text/plain' is telling you that the page is not html. Are you saying that the page is actually html even though the page says that it does not contain html? -- Posted via http://www.ruby-forum.com/.