运行此块时,我一直收到以下输出。它就像用户'链接(在puts语句中显示正常)不会被转换为links_with方法中的正确链接:
https://www.reddit.com/r/aww/#content
应该链接到用户的个人资料页面(即/ username而不是#content)。
require 'mechanize'
mechanize = Mechanize.new
page = mechanize.get('https://www.reddit.com/r/aww/')
page.xpath('//*[contains(@class,"tagline")]/a[contains(@href,"user/")]/@href').each do |user|
puts user
new_page = page.link_with(user).click
puts new_page.uri
end