【发布时间】:2017-12-20 13:04:39
【问题描述】:
在这个项目上我必须抓取一个“网站”,这只是一个本地文件夹中的一个 html 文件。无论如何,我一直在尝试为每个 student 对象搜索锚标记的 href 值(一个 url)。我也在寻找其他的东西,所以忽略其余的。这是我目前所拥有的:
def self.scrape_index_page(index_url) #responsible for scraping the index page that lists all of the students
#return an array of hashes in which each hash represents one student.
html = index_url
doc = Nokogiri::HTML(open(html))
# doc.css(".student-name").first.text
# doc.css(".student-location").first.text
#student_card = doc.css(".student-card").first
#student_card.css("a").text
end
这是其中一份学生资料。它们都是一样的,所以我只是对抓取 href url 值感兴趣。
<div class="student-card" id="eric-chu-card">
<a href="students/eric-chu.html">
<div class="view-profile-div">
<h3 class="view-profile-text">View Profile</h3>
</div>
<div class="card-text-container">
<h4 class="student-name">Eric Chu</h4>
<p class="student-location">Glenelg, MD</p>
</div>
</a>
</div>
感谢您的帮助!
【问题讨论】:
-
你的问题是什么?
-
请分享
url或html文档样本 -
我正在尝试获取学生卡类容器的 href 值。
标签: ruby nokogiri screen-scraping scrape