2014-09-08 3 views
0

나는이 언어로 새로운데, 나는 간단한 작업에 빠져있다.WebHarvest가 하나의 요청으로 결과 50 개 필요

기본적으로 검색자가 기본 결과로 제공하는 10 가지 기본 검색 결과 대신 50 가지 검색 결과를 얻고 싶습니다. 이 코드가 될 것입니다!

<include path="functions.xml"/> 
<!-- The phrase to search for in the 4shared API --> 
<var-def name="searchPhrase">Adele Rolling In The Deep</var-def> 

<!-- The type of sorting that the 4shared API will use (2 = sort by upload date) --> 
<var-def name="sortType">2</var-def> 

<!-- The order for search results (-1 = ascending) --> 
<var-def name="sortOrder">-1</var-def> 

<!-- The page to start the search on (the API returns 10 results per page) --> 
<var-def name="start">1</var-def> 

<!-- Make a web request to the 4shared search API and store the XML returned in the 'pageXml' variable --> 
<while condition="true" index="start" maxloops="5"> 
    <var-def name="pageXml" overwrite="true"> 

      <http url="http://search.4shared.com/network/searchXml.jsp" charset="UTF8"> 
      <http-param name="q"><template>${searchPhrase}</template></http-param> 
      <http-param name="sortType"><template>${sortType}</template></http-param> 
      <http-param name="sortOrder"><template>${sortOrder}</template></http-param> 
      <http-param name="start"><template>${start}</template></http-param> 
    </http> 

    </var-def> 
</while> 
<file action="write" type="text" path="xml/pageXml.xml"> 
    <var name="pageXml"></var> 
</file> 


<!-- Extract all 'url' nodes from the XML returned from the API call using XPath. 
    The xpath expression used here is '//result-files/file/url/text()' meaning return the text value of all 
    'url' nodes with a 'file' node, within a 'result-files' node. 
--> 
<var-def name="urls" overwrite="true"> 
    <xpath expression="//result-files/file/url/text()"> 
     <var name="pageXml"/> 
    </xpath> 
</var-def> 

<!-- Extract all 'name' nodes from the XML returned from the API call using XPath --> 


<!-- Extract all 'downloads-count' nodes from the XML returned from the API call using XPath --> 
<var-def name="downloadsCount"> 
    <xpath expression="//result-files/file/downloads-count/text()"> 
     <var name="pageXml"/> 
    </xpath> 
</var-def> 
<file action="write" type="text" path="xml/downloadsAverage.xml"> 
      <var name="downloadsCount"></var> 
</file> 
<!-- Extract all 'size' nodes from the XML returned from the API call using XPath --> 
<var-def name="size"> 
    <xpath expression="//result-files/file/size/text()"> 
     <var name="pageXml"/> 
    </xpath> 
</var-def> 
<file action="write" type="text" path="xml/size.xml"> 
      <var name="size"></var> 
</file> 




<!-- Calculate the average number of downloads. 
    Note that the <script> tag is used in order to interact with the variables using beanscript, 
    which is a Java like language. 
    Previously defined variables can be accessed directly, and a toList() method can be called to convert them into 
    a List, and then individual items can be accessed by called the standard List method of get(), and then finally 
    toString() can be called to convert individual items to Strings. 
--> 
<var-def name="averageDownloads"> 
    <script return="returnVariable"><![CDATA[ 
     var downloadsCountSize = downloadsCount.toList().size(); 
     var totalDownloads = 0; 

     for(int i = 0; i < downloadsCountSize; i++) { 
      totalDownloads = totalDownloads + new Integer(downloadsCount.toList().get(i).toString().replace(",","")); 
     } 

     var returnVariable = totalDownloads/downloadsCountSize; 
    ]]></script> 
</var-def> 
<file action="write" type="text" path="xml/avgDownloads.xml"> 
      <var name="averageDownloads"></var> 
</file> 

사람이 내가이 문제를 해결하는 방법을 말할 수 ??? 부디!!

답변

0

while 루프 (</while>)를 너무 일찍 종료했습니다. <while>...</while> 내부

만 문 만 결과의 마지막 페이지를 처리하는 것을 의미한다 반복됩니다

따라서 나는 당신의 </while> 생각 (... pageXml.xml, 추출물 'URL'노드 등을 쓰기) 여기에 게시 한 코드의 끝에 표시되어야합니다.