2
我在嘗試發現從Nokogiri節點檢索href鏈接的最佳方法。下面是我在從Mechanize/Nokogiri獲取鏈接
mech = Mechanize.new
mech.get(HOME_URL)
mech.page.search('.listing_content').each do |business|
website = business.css('.website-feature')
puts website.class
puts website.inner_html
end
輸出=>
Nokogiri::XML::NodeSet <a href="http://urlofsite.com" class="track-visit-website no-tracks" onclick='omniture.callClick({"eVar6":6,"eVar9":1,"eVar21":"search_results","eVar50":null,"prop17":"cars","prop26":"64c15af0-a558-012f-a041-00215a4685f6","eVar42":"64c15af0-a558-012f-a041-00215a4685f6","prop27":6,"prop38":"search_results","prop39":1,"prop46":null,"events":"event6,event7","eVar51":optimostIDs.trialID.toString(),"eVar52":optimostIDs.segmentID.toString(),"eVar53":optimostIDs.creativeID.toString(),"eVar54":optimostIDs.subjectID.toString(),"prop47":null,"prop51":optimostIDs.trialID.toString(),"prop52":optimostIDs.segmentID.toString(),"prop53":optimostIDs.creativeID.toString(),"prop54":optimostIDs.subjectID.toString(),"prop56":"Saint+George%2C+UT","prop57":null,"prop58":false,"prop59":null,"eVar60":"relevancyTest2","prop60":"relevancyTest2","prop61":false,"prop62":null,"prop64":null,"prop67":null,"prop68":null,"prop70":null,"prop71":null});; atti_logs.attiClick({"iid":"651691e0-a558-012f-2ca7-18a9053c171a","lt":6,"ptid":"www.yellowpages.com","rid":"vendetta-236e7298-3a4f-4744-8ff5-4eb5fcc8e188","ypid":3848879,"lid":3848879,"vrid":"64c15af0-a558-012f-a041-00215a4685f6","nav":null});' rel="nofollow" target="_blank" title="Executive Service Ctr Website"><span class="raquo">»</span> Website</a>
基本上在那裏,我只需要得到http://urlofsite.com
出inner_html
的,我不知道該怎麼做。我已經閱讀了關於使用CSS和XPATH來做這件事,但是我現在無法在這一點上工作。感謝任何幫助
感謝您的信息。每當我嘗試用at_css('a.track-visit-website no-tracks')抓取節點時,它都會返回一個nilclass。我要編輯我的文章繼續前進,並看看 – ruevaughn
經過一段時間後,我能夠完全按照你所描述的來完成它。謝謝你的幫助,錫人終究有一顆心;) – ruevaughn
我很高興它的工作。 Nokogiri是一個很棒的XML/HTML解析器,所以感謝這個團隊。 –