如何在Mechanize和Nokogiri中单击链接? [英] How to click link in Mechanize and Nokogiri?
问题描述
我正在使用Mechanize抓取Google电子钱包中的订单数据.我正在捕获第一页中的所有数据,但是,我需要自动链接到后续页面以获取更多信息.
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.
#purchaseOrderPager-pagerNextButton将移至下一页,因此我可以提取更多记录以进行捕获.元素看起来像这样.我需要单击它才能继续.
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&...
;currentPageStart=1&currentPageEnd=25&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
错误:
undefined method `click' for #<Nokogiri::XML::NodeSet:0x007f9019095550> (NoMethodError)
推荐答案
click
是 Mechanize
类的方法.
click
is a method of Mechanize
class.
请尝试填写以下表格.
next_page = @orders_page.at("#purchaseOrderPager-pagerNextButton")
mechanize_instance.click(next_page)
注意,将mechanize_instance
替换为实际变量.
NOTE Replace mechanize_instance
with actual variable.
这篇关于如何在Mechanize和Nokogiri中单击链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!