【问题标题】:Adding numbers to variables in WebHarvest将数字添加到 WebHarvest 中的变量
【发布时间】:2014-07-18 06:32:01
【问题描述】:

首先我应该说我对 javascript 很陌生。

我需要根据一个数字向 webharvest 提供一堆 url。这是一个很长的故事,但我的 url 结构看起来像这样: http://www.example.com/foo/bar?page=0?page= 每一步增加 25。所以下一页将是http://www.example.com/foo/bar?page=25,然后是http://www.example.com/foo/bar?page=50,依此类推。有一个最大值,我可以通过另一个变量来设置,称之为${maxpages}

所以我需要做的是修改一个变量以输入其他完全可预测的 url,以便每次添加 25 个变量。我正在考虑做一个while 循环,如下所示:

<var-def name="pageNo">0</var-def>
<while condition="${pageNo} < ${maxpages}">
    <body>
        <html-to-xml><http url="${url}?${pageNo}"/></html-to-xml>
        <var-def name="pageNo">
            <var name="pageNo">[this is where I want to add 25]</var>
        </var-def>
    </body>
</while>

所以我真的不确定这里的语法。

我的问题是:

  1. 如何检查我的变量 pageNo 在 while 条件下是否小于 maxpages?

  2. 可以在 webharvest 中将整数添加到变量中吗?怎么样?

【问题讨论】:

    标签: webharvest


    【解决方案1】:

    我想我正在养成回答自己的习惯。

    经过一个小时的反复试验,我得到了这个:

    <var-def name="commentCount">432</var-def>
    <var-def name="pageNo">0</var-def>
    <while condition="${pageNo.toInt() &lt; commentCount.toInt()}">
        <html-to-xml>
            <http url="http://www.example.com/foo/bar?${pageNo}"/>
        </html-to-xml>
        <var-def name="pageNo"><template>${pageNo.toInt() + 25}</template></var-def>
    </while>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 2022-11-23
      • 2017-09-09
      • 1970-01-01
      • 2011-07-03
      • 1970-01-01
      相关资源
      最近更新 更多