0

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

我需要根据一个数字向 webharvest 提供一堆 url。这是一个很长的故事,但我的 url 结构看起来像这样: http://www.example.com/foo/bar?page=0. ?page=每步增加25。所以下一页将是http://www.example.com/foo/bar?page=25thenhttp://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 中的变量吗?如何?

4

1 回答 1

0

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

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

<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>
于 2014-07-18T07:21:13.433 回答