【问题标题】:Web-Harvest: grabbing multiple url's from a listWeb-Harvest:从列表中获取多个 url
【发布时间】:2013-07-31 23:29:48
【问题描述】:

我正在尝试从预定义列表中获取多个网页。 代码如下:

<?xml version="1.0" encoding="UTF-8"?>
    <config>

      <script>
            <![CDATA[
                String[] codes = new String[] {"18","21","24","25","26"};
                SetContextVar("codes", codes);
            ]]>
      </script>
      <loop item="link">
            <list>
                <var name="codes" />
            </list>
            <body>

              <var-def name="webpage">
                  <html-to-xml>                                 
                    <http url="${sys.fullUrl('http://www.someurl.com/',link)}"/>            
                  </html-to-xml>
              </var-def> 
            </body>
        </loop>
    </config>

错误是“变量分配:代码:无法将 org.webharvest.runtime.variables.ListVariable 分配给 java.lang.String”

我在这里错过了什么?

【问题讨论】:

    标签: xml web-crawler webharvest


    【解决方案1】:

    请试试这个例子:

    <config>
    
      <var-def name="Codes">
        <![CDATA[<Codes>]]>
        <![CDATA[<Code>]]>18<![CDATA[</Code>]]>
        <![CDATA[<Code>]]>21<![CDATA[</Code>]]>
        <![CDATA[<Code>]]>24<![CDATA[</Code>]]>
        <![CDATA[<Code>]]>25<![CDATA[</Code>]]>
        <![CDATA[</Codes>]]>
      </var-def>
    
      <loop item="CodesLoop" index="i">
        <list>
          <xpath expression="//Code/text()">
            <var name="Codes"/>
          </xpath>
        </list>
        <body>
          <file action="write" path="D:\ABC\${CodesLoop}.txt" charset="UTF-8">
            <template>${CodesLoop}</template>
          </file>
        </body>
      </loop>
    </config>
    

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多