Felipe Jordão A. P. Mattosinho
2010-Jan-19 01:48 UTC
[Mechanize-users] RES: How to click on a link, in a specific part of the web page! Help
Hi Matt, Thanks for your reply. Each solved the problem! Regards! _____ De: mattw922 at gmail.com [mailto:mattw922 at gmail.com] Enviada em: ter?a-feira, 19 de janeiro de 2010 00:39 Para: Felipe Jord?o A. P. Mattosinho Assunto: Re: [Mechanize-users] How to click on a link, in a specific part of the web page! Help Felipe, Where you have: pre_page.search(XPATH_TO_FIRST_LINK_RESULT_PAGE) do |result| @last_page = WWW::Mechanize::Page::Link.new(result,@@mech, at pre_page).click You should have: pre_page.search(XPATH_TO_FIRST_LINK_RESULT_PAGE).each do |result| @last_page = WWW::Mechanize::Page::Link.new(result,@@mech,pre_page).click Notice the .each and the removal of an @. Worked for me. Matt On Jan 18, 2010 2:40pm, "Felipe Jord?o A. P. Mattosinho" <felipemattosinho at terra.com.br> wrote:> > > > > > > > > > > > > > Hi everybody, > > > > I am a new Ruby programmer and Mechanize & > Nokogiri user. I am using the both gems however for my master thesis, andsince> I can?t see much documentation for mechanize on the internet I have a > question. > > > > > > URL > ''http://reviews.cnet.com'' > > SEARCH_FIELD_NAME = ''tsearch'' > > XPATH_TO_RESULT_PAGE "/html/body/div[2]/div/div[2]/div[3]/div[2]/form/ul" > > > XPATH_TO_FIRST_LINK_RESULT_PAGE > "/html/body/div[2]/div/div[2]/div[3]/div[2]/form/ul/li/div[4]/a" > > > > @@mech = WWW::Mechanize.new > > > > # Creates an instance of Mechanize > and select CNET Website > > > > page = @@mech.get(URL) > > > > > > search_form = page.form(SEARCH_FIELD_NAME) > > > > search_form.query = query > > > > pre_page > = @@mech.submit(search_form, > search_form.buttons.first) > > > > pre_page.search(XPATH_TO_FIRST_LINK_RESULT_PAGE) do |result| > > > > @last_page WWW::Mechanize::Page::Link.new(result,@@mech, at pre_page).click > > > > end > > > > My problem is with the variable @last_page. I am not > so sure if I am doing something but I believe I am. I mean that was theonly> way I found to do what I wanted to. > > On the variable pre_page I search for a specific field > where results are present. I cannot rely just on the name of the linkbecause> links with the name of my search can be everywhere on this page. That iswhy I want> to specify just a part of the page where a link with the name of my query > should be clicked. That was the only way that I found to restrict thelinks> that I want to click. The problem is that I tried to make a new link,based on> the result (which is correct, that was the link I was searching for), andto> click on it to proceed to the next page. However @last_page is always niland> this is not working. If someone has a good idea or how can I make itcorrect ,> please send me a reply! > > > > Best Regards > > > > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/mechanize-users/attachments/20100119/256177e9/attachment.html>