我已经登录到Linkedin,并使用Ruby机械化登录到我的群组页面。我还可以检索页面上的问题列表。但是,我无法单击底部的“显示更多”链接,以便我可以查看整个页面以及所有问题:
require 'rubygems'
require 'mechanize'
require 'open-uri'
a = Mechanize.new { |agent|
# LinkedIn probably refreshes after login
agent.follow_meta_refresh = true
}
a.get('http://linkedin.com/') do |home_page|
my_page = home_page.form_with(:name => 'login') do |form|
form.session_key = '********' #put you email ID
form.session_password = '********' #put your password here
end.submit
mygroups_page = a.click(my_page.link_with(:text => /Groups/))
#puts mygroups_page.links
link_to_analyse = a.click(mygroups_page.link_with(:text => 'Semantic Web'))
link_to_test = link_to_analyse.link_with(:text => 'Show more...')
puts link_to_test.class
# link_to_analyse.search(".user-contributed .groups a").each do |item|
# puts item['href']
# end
end尽管存在文本为“Show more...”的链接在页面中,我不知何故无法单击it.the link_to_test.class shows NilClass什么是可能的问题?
The part of the page I need to reach is:
<div id="inline-pagination">
<span class="running-count">20</span>
<span class="total-count">1134</span>
<a href="groups?mostPopularList=&gid=49970&split_page=2&ajax=ajax" class="btn-quaternary show-more-comments" title="Show more...">
<span>Show more...</span>
<img src="http://static01.linkedin.com/scds/common/u/img/anim/anim_loading_16x16.gif" width="16" height="16" alt="">
</a>
</div>我需要点击显示更多...我可以使用links_with(:href => ..)但似乎不起作用。
发布于 2012-07-23 11:29:10
锚点内的标签将在锚点文本周围创建一些空白。您可以使用以下命令来说明这一点:
link_to_analyse.link_with :text => /\A\s*Show more...\s*\Z/但它可能已经足够好了,可以这样做:
link_to_analyse.link_with :text => /Show more.../发布于 2012-07-23 10:38:19
新答案:
我刚刚检查了该组的页面源代码,似乎“显示更多”链接实际上使用了三个句号字符,而不是省略号。
您是否尝试过通过链接的title属性来确定链接的目标?
link_to_analyse.link_with(:title => 'Show more...')如果这仍然不起作用,你有没有尝试过用转储页面上所有链接的文本
link_to_analyse.links.each do |link|
puts link.text
end-旧答案不正确-
LinkedIn使用“水平省略号”Unicode字符(代码U+2026)来表示他们的链接,“看起来”就像他们有"...“在最后。因此,您的代码实际上并没有找到链接。
您需要的字符:http://www.fileformat.info/info/unicode/char/2026/index.htm
偷偷摸摸:)
编辑:当然,要获得链接,您需要在链接文本中插入适当的Unicode字符,如下所示:
link_to_analyse.link_with(:text => 'Show more\u2026')https://stackoverflow.com/questions/11605766
复制相似问题