在问答论坛中抓取日期
scrape date in Q&A forum
在此线程中
https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html
我正在尝试查找每个 post
的日期
我能找到这个
css="td.thead:first-child"
所以当我运行这个
html_text(html_nodes(read_html("https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html"), css="td.thead:first-child"))
我得到日期
[1] " \r\n\t\t\t05-13-2013, 11:06 AM\r\n\t\t\t\r\n\t\t\t " "Sponsors " " \r\n\t\t\t07-26-2013, 08:15 AM\r\n\t\t\t\r\n\t\t\t "
[4] " \r\n\t\t\t04-26-2014, 06:28 PM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t05-07-2014, 02:43 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t09-19-2014, 07:28 AM\r\n\t\t\t\r\n\t\t\t "
[7] " \r\n\t\t\t09-19-2014, 07:29 AM\r\n\t\t\t\r\n\t\t\t " "Thread Tools" " \r\n\t\tPosting Rules\r\n\t"
[10] "LinkBack" "Bookmark & Share"
我得到了日期,还有 "Thread tools"、"Posting Rules" 和 "Bookmark & Share"..我做错了什么?
您用来匹配日期的 CSS 样式似乎也可以在页面的其他地方找到,从而返回那些其他条目。您可以使用 CSS Selector 只查看 ID 以 'post' 开头的表。选择器是 table[id^='post']
,完整的解决方案是:
html_text(html_nodes(read_html("https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html"), css="table[id^='post'] td.thead:first-child"))
[1] " \r\n\t\t\t05-13-2013, 11:06 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t07-26-2013, 08:15 AM\r\n\t\t\t\r\n\t\t\t "
[3] " \r\n\t\t\t04-26-2014, 06:28 PM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t05-07-2014, 02:43 AM\r\n\t\t\t\r\n\t\t\t "
[5] " \r\n\t\t\t09-19-2014, 07:28 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t09-19-2014, 07:29 AM\r\n\t\t\t\r\n\t\t\t "
在此线程中
https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html
我正在尝试查找每个 post
的日期我能找到这个
css="td.thead:first-child"
所以当我运行这个
html_text(html_nodes(read_html("https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html"), css="td.thead:first-child"))
我得到日期
[1] " \r\n\t\t\t05-13-2013, 11:06 AM\r\n\t\t\t\r\n\t\t\t " "Sponsors " " \r\n\t\t\t07-26-2013, 08:15 AM\r\n\t\t\t\r\n\t\t\t "
[4] " \r\n\t\t\t04-26-2014, 06:28 PM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t05-07-2014, 02:43 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t09-19-2014, 07:28 AM\r\n\t\t\t\r\n\t\t\t "
[7] " \r\n\t\t\t09-19-2014, 07:29 AM\r\n\t\t\t\r\n\t\t\t " "Thread Tools" " \r\n\t\tPosting Rules\r\n\t"
[10] "LinkBack" "Bookmark & Share"
我得到了日期,还有 "Thread tools"、"Posting Rules" 和 "Bookmark & Share"..我做错了什么?
您用来匹配日期的 CSS 样式似乎也可以在页面的其他地方找到,从而返回那些其他条目。您可以使用 CSS Selector 只查看 ID 以 'post' 开头的表。选择器是 table[id^='post']
,完整的解决方案是:
html_text(html_nodes(read_html("https://www.healthboards.com/boards/aspergers-syndrome/949512-im-lost.html"), css="table[id^='post'] td.thead:first-child"))
[1] " \r\n\t\t\t05-13-2013, 11:06 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t07-26-2013, 08:15 AM\r\n\t\t\t\r\n\t\t\t "
[3] " \r\n\t\t\t04-26-2014, 06:28 PM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t05-07-2014, 02:43 AM\r\n\t\t\t\r\n\t\t\t "
[5] " \r\n\t\t\t09-19-2014, 07:28 AM\r\n\t\t\t\r\n\t\t\t " " \r\n\t\t\t09-19-2014, 07:29 AM\r\n\t\t\t\r\n\t\t\t "