WebHarvest无法找到响应标头

时间:2012-10-23 18:53:27

标签: webharvest

我正在使用WebHarvest从需要登录的站点获取数据。

它的设置如下:

第1页=登录页面

第2页=登录验证页面

第3页=统计页面

在第2页上设置了一个cookie。当用Firebug监视开放时,我得到了这些标题:

Connection  Keep-Alive
Content-Type    text/html; charset=UTF-8
Date    Tue, 23 Oct 2012 18:25:12 GMT
Keep-Alive  timeout=15, max=100
Server  Apache/2.0.64 (Win32) JRun/4.0 SVN/1.3.2 DAV/2
Set-Cookie  SESSION=hej123;expires=Thu, 16-Oct-2042 18:25:12 GMT;path=/
Transfer-Encoding   chunked

当使用WebHarvest调用同一页面时,我只获得这些标题:

Date=Tue, 23 Oct 2012 18:31:51 GMT
Server=Apache/2.0.64 (Win32) JRun/4.0 SVN/1.3.2 DAV/2
Transfer-Encoding=chunked
Content-Type=text/html; charset=UTF-8

似乎WebHarvest找不到三个标题(Set-Cookie,Connection和Keep-Alive)。第1页,第2页和第3页是dummys,因此没有进行实际验证。 cookie总是在第2页的服务器端设置。

以下是我目前正在使用的WebHarvest代码:

<var-def name="content2">
<html-to-xml>
<http method="post" url="http://myurl.com/page2.cfm">
    <http-param name="Login">sigge</http-param>
    <http-param name="Password">hej123</http-param>
    <http-param name="doLogin">Logga in</http-param>
    <loop item="currField">
        <list>
            <var name="ctxtNewInputs" />
        </list>
        <body>
             <script><![CDATA[
                item = (NvPair) currField.getWrappedObject();
                SetContextVar("itemName", item.name);
                SetContextVar("itemValue", item.value);
            ]]></script>
            <http-param name="${item.name}"><var name="itemValue" /></http-param>
        </body>
    </loop>
     <script><![CDATA[
        String keys="";
        for(int i=0;i<http.headers.length;i++) {
            keys+=(http.headers[i].key + "=" + http.headers[i].value +"\n---\n");
        }
        SetContextVar("myCookie", keys);
    ]]></script>
    <file action="write" path="c:/kaka.txt">
        <var name="myCookie"/>
    </file>        
</http>
</html-to-xml>
</var-def>

编辑: 在检查时我发现cookie已在WebHarvest中设置,即使无法以编程方式找到http标头。是否有可能隐藏某些响应标头?

有没有人知道这个问题的解决办法?

谢谢你,最诚挚的问候, SiggeLund

1 个答案:

答案 0 :(得分:1)

将http标头值转换为整个配置范围的用户定义变量的方法如下:

<http url="your.url.here" method="GET">
    <!--Any settings you apply for the POST/GET call-->
</http>
<!--Now you've got your http object you are going to get header value from -->
<!--At it simplest the acquisition of value goes like the below-->
<var-def name="fifth_header_val">
      <script return="http.headers[5].value"/>
</var-def>

以上只是为了给出一个线索。您可以迭代http.headers索引并收集特定任务所需的键和值。

相关问题