Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click link in Mechanize and Nokogiri?

I'm using Mechanize to scrape Google Wallet for Order data. I am capturing all the data from the first page, however, I need to automatically link to subsequent pages to get more info.

The #purchaseOrderPager-pagerNextButton will move to the next page so I can pick up more records to capture. The element looks like this. I need to click on it to keep going.

<a id="purchaseOrderPager-pagerNextButton" class="kd-button small right"
 href="purchaseorderlist?startTime=0&amp;...
;currentPageStart=1&amp;currentPageEnd=25&amp;inputFullText=">
<img src="https://www.gstatic.com/mc3/purchaseorder/page-right.png"></a>

However, when I try the following I get an error:

  next_page = @orders_page.search("#purchaseOrderPager-pagerNextButton")
  next_page.click

The error:

undefined method `click' for #<Nokogiri::XML::NodeSet:0x007f9019095550> (NoMethodError)
like image 468
analyticsPierce Avatar asked Jan 12 '23 03:01

analyticsPierce


1 Answers

click is a method of Mechanize class.

Try following form.

next_page = @orders_page.at("#purchaseOrderPager-pagerNextButton")
mechanize_instance.click(next_page)

NOTE Replace mechanize_instance with actual variable.

like image 149
falsetru Avatar answered Jan 21 '23 23:01

falsetru