【发布时间】:2016-08-06 10:05:31
【问题描述】:
我在 csv 文件中有一个包含 40,000 个网页地址的列表。我想在一个新的 csv 文件中读取这些页面,以便 csv 中的每个单元格都是相关网页的内容。 我可以使用以下代码读取(解析)单个网页
library(XML)
# Read and parse HTML file
doc.html = htmlTreeParse('',useInternal = TRUE)
# Extract all the paragraphs (HTML tag is p, starting at
# the root of the document). Unlist flattens the list to
# create a character vector.
doc.text = unlist(xpathApply(doc.html, '//p', xmlValue))
# Replace all \n by spaces
doc.text = gsub('\\n', ' ', doc.text)
# Join all the elements of the character vector into a single
# character string, separated by spaces
doc.text = paste(doc.text, collapse = ' ')
是否可以使用以网页地址为输入的 csv 并获取包含上述所有内容的新文件?
【问题讨论】:
-
帮助你编写代码的人应该意识到他们正在帮助那些最有可能违反许多网站的服务条款的人(这里是 Mashable 的):“你不能使用蜘蛛、机器人、数据挖掘技术或其他自动化设备或程序来编目、下载或以其他方式复制、存储或分发服务上可用的内容。”
-
这只是我给出的一个例子。我没有从 mashable 中收集数据。
-
所以您证明您已验证您遵守 40,000 个 URL 所代表的网站的服务条款,或者已联系了每个有限制并获得许可的网站?跨度>
-
我正在使用 UCI 上的公开数据