gpt4 book ai didi

ruby - 如何使用 Mechanize Ruby 模拟跨度点击?

转载 作者:行者123 更新时间:2023-12-04 16:22:50 29 4
gpt4 key购买 nike

我有一个包含页面列表的网页:

<div class="pager">    
<span class="current_page">1</span>
<span class="page" samo:page="2">2</span>
<span class="page" samo:page="3">3</span>
<span class="page" samo:page="4">4</span>
<span class="page" samo:page="5">5</span>
<span class="page" samo:page="6">6</span>
<span class="page" samo:page="7">7</span>
<span class="page" samo:page="8">8</span>
<span class="page" samo:page="9">9</span>
<span class="page" samo:page="10">10</span>
<span class="page" samo:page="11">11</span>
</div>

如何使用 Mechanize 单击跨度?

最佳答案

根据此 ASCIIcasts,您可以执行搜索和发现:

There are two methods on the page object that we can use to extract elements from a page using Nokogiri. The first of these is called at and will return a single element that matches a selector.

agent.page.at(".edit_item")  

The second method is search. This is similar, but returns an array of all of the elements that match.

agent.page.search(".edit_item")


http://asciicasts.com/episodes/191-mechanize

所以做这样的事情:
agent.page.at(".page")

将返回跨度数组。然后您将能够与他们一起工作,只需执行#click 操作即可。

编辑:

只要 span 是一个非交互元素,而 click 是一个 Link Action ,你就必须找到一个解决方法:

How to click link in Mechanize and Nokogiri?

关于ruby - 如何使用 Mechanize Ruby 模拟跨度点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26302185/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com