1

Linkedinにログインし、RubyMechanizeを使用してグループページにアクセスしました。ページ上の質問のリストを取得することもできます。ただし、下部にある[もっと見る]リンクをクリックして、ページ全体、つまりすべての質問を表示することができません。

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

ページに「Showmore...」というテキストのリンクがありますが、どういうわけかクリックできません。link_to_test.classに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=&amp;gid=49970&amp;split_page=2&amp;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 => ..)を使用できますが、機能しないようです。

4

2 に答える 2

1

新しい答え:

グループのページ ソースを調べたところ、「もっと見る」リンクでは、省略記号ではなく 3 つのピリオド文字が実際に使用されているようです。

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')
于 2012-07-23T02:38:18.530 に答える
0

アンカー内のタグは、アンカー テキストの周りに空白を作成します。あなたはそれを説明することができます:

link_to_analyse.link_with :text => /\A\s*Show more...\s*\Z/

しかし、おそらく次のようにするだけで十分です。

link_to_analyse.link_with :text => /Show more.../
于 2012-07-23T03:29:10.023 に答える