首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebHarvest找不到响应头

WebHarvest找不到响应头
EN

Stack Overflow用户
提问于 2012-10-24 02:53:27
回答 1查看 615关注 0票数 1

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

它是这样设置的:

第1页=登录页

第2页=登录验证页面

第3页=统计页面

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

代码语言:javascript
复制
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调用同一页面时,我只得到以下标题:

代码语言:javascript
复制
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页是虚拟的,因此不会进行实际的验证。cookie始终设置在第2页的服务器端。

下面是我目前使用的WebHarvest代码:

代码语言:javascript
复制
<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

EN

回答 1

Stack Overflow用户

发布于 2015-05-06 00:38:45

将http标头值获取到整个配置的用户定义变量作用域的方法如下:

代码语言:javascript
复制
<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索引并收集特定任务所需的键和值。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13037219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档