调试R的XML库中的htmlParse

时间:2012-07-29 19:36:29

标签: r debugging xml-parsing

这不是我第一次在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

我很高兴看到那里有什么东西,但我在哪里深入了解过去&#34;错误:文件&#34;?

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

如何像这样从htmlParse调试错误?

1 个答案:

答案 0 :(得分:3)

首先下载然后传递给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)

似乎也很好