【问题标题】:Debugging htmlParse in R's XML library在 R 的 XML 库中调试 htmlParse
【发布时间】:2012-07-27 13:53:39
【问题描述】:

这不是我第一次在 XML 库中使用htmlParse 时遇到问题,但过去我刚刚放弃并使用 来解析我需要的内容。我宁愿通过解析 XML/XHTML 来做到这一点,因为我们都知道正则表达式不是解析器。

也就是说,我发现解析命令中的错误消息充其量是没有帮助的,我不知道如何继续。例如:

> htmlParse(getForm("http://www.takecarehealth.com/LocationSearchResults.aspx", location_query="Deer Park",location_distance=50))
Error in htmlParse(getForm("http://www.takecarehealth.com/LocationSearchResults.aspx",  : 
  File 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="ctl00_Head1">
        <title></title>
        <script language="JavaScript" type="text/javascript">
            var s_pageName = document.title;
            var s_channel = "Take Care";
            var s_campaign = "";
            var s_eVar1 = ""
            var s_eVar2 = ""
            var s_eVar22 = ""
            var s_eVar23 = ""
        </script>
        <meta name="keywords" content="take care clinic, walgreens clinic, walgreens take care clinic, take care health, urgent care clinic, walk in clinic" />
        <meta name="description" content="Information about simple, quality healthcare for the whole family from Take Care Clinics at select Walgreens, including Take Care Clinic hours, providers, offers, insurance and quality of care." />
        <link rel="shortcut icon" hre

我很高兴它在那里看到了一些东西,但是我在哪里可以深入了解“错误:文件”?

请注意,据我所知,这是格式良好的 XHTML。当我访问link manually 时,我可以在其上运行 xpaths,而 Firebug 不会抱怨。

我该如何调试来自 htmlParse 的错误?

【问题讨论】:

  • @ttmaccer 很有趣。所以这毕竟是一个格式错误的代码问题。
  • 这很有意义。谢谢。

标签: regex r debugging xml-parsing


【解决方案1】:

先下载然后传递给 XML 包似乎可以工作

test<-getForm("http://www.takecarehealth.com/LocationSearchResults.aspx", location_query="Deer Park",location_distance=50)
htmlParse(test,asText=T)

或直接

htmlParse(getForm("http://www.takecarehealth.com/LocationSearchResults.aspx", location_query="Deer Park",location_distance=50),asText=T)

好像也不错

【讨论】:

  • 所以我猜是 asText 参数做到了?
猜你喜欢
  • 1970-01-01
  • 2014-02-08
  • 2011-03-23
  • 2012-09-11
  • 2014-03-31
  • 2013-03-14
  • 2012-11-09
  • 2021-02-25
  • 2022-06-11
相关资源
最近更新 更多