100分求大神写个例子 用web harvest爬取网页拿http://www.fenzhi.com/xsc1p1.html为例
一下是我写的脚本
<?xml version="1.0" encoding="UTF-8"?>
<config>
<include path="functions.xml" />
<file action="write" path="fz/2.xml" charset="UTF-8">
<![CDATA[<catalog>]]>
<empty>
<var-def name="priceList" id="priceList">
<xpath expression="//div[@class='winnerLink']">
<html-to-xml>
<http url="http://www.fenzhi.com/xsc1p1.html" />
</html-to-xml>
</xpath>
</var-def>
</empty>
<loop item="item" index="i">
<list>
<var name="priceList"></var>
</list>
<body>
<xquery>
<xq-param name="item" type="node()">
<var name="item" />
</xq-param>
<xq-expression>
<![CDATA[
declare variable $item as node() external;
let $name :=data($item)
return
<info name='{normalize-space($name)}'>
<name>{normalize-space($name)}</name>
</info>
]]>
</xq-expression>
</xquery>
</body>
</loop>
<![CDATA[</catalog>]]>
</file>
</config>
我想要的结果是在http://www.fenzhi.com/xsc1p1.html页面爬取到 华为 ibm这样的名字存起来 然后再爬取到超链接 比如gsx3131.html 然后用这个超链接和www.fenzhi.com拼接到一起 成新的url 进入到这个url后爬取公司简介
目前比较困惑的是 怎么在同一个loop里去循环2个结果集 总是合在一起 哎
一下是我写的脚本
<?xml version="1.0" encoding="UTF-8"?>
<config>
<include path="functions.xml" />
<file action="write" path="fz/2.xml" charset="UTF-8">
<![CDATA[<catalog>]]>
<empty>
<var-def name="priceList" id="priceList">
<xpath expression="//div[@class='winnerLink']">
<html-to-xml>
<http url="http://www.fenzhi.com/xsc1p1.html" />
</html-to-xml>
</xpath>
</var-def>
</empty>
<loop item="item" index="i">
<list>
<var name="priceList"></var>
</list>
<body>
<xquery>
<xq-param name="item" type="node()">
<var name="item" />
</xq-param>
<xq-expression>
<![CDATA[
declare variable $item as node() external;
let $name :=data($item)
return
<info name='{normalize-space($name)}'>
<name>{normalize-space($name)}</name>
</info>
]]>
</xq-expression>
</xquery>
</body>
</loop>
<![CDATA[</catalog>]]>
</file>
</config>
我想要的结果是在http://www.fenzhi.com/xsc1p1.html页面爬取到 华为 ibm这样的名字存起来 然后再爬取到超链接 比如gsx3131.html 然后用这个超链接和www.fenzhi.com拼接到一起 成新的url 进入到这个url后爬取公司简介
目前比较困惑的是 怎么在同一个loop里去循环2个结果集 总是合在一起 哎
解决方案 »
- HttpClient 获取图片的一个问题
- 关于socket通信慢的问题
- hibernate缓存问题...燃眉呀
- 关于Eclipse导入jar的问题
- 貌似TOMCAT5.5.17不支持J2EE1.5,还是tomcatPluginV31不支持?
- [求助]]<logic:iterate/>嵌套<logic:iterate/>显示的checkbox如何取选中的值(急)
- closeSession什么时候应该用?
- JDOM中有个直接把RecordSet对象转化为XML片段的方法,昨天看过,今天忘记了。
- struts,简单的联接问题,急!!!!
- 如何定义BOM表在CMP中的关系?
- 想自己定义错误接口和对应的代码,但是不知道如何将错误代码在jsp页面弹出
- 求助:大神们,给点建议吧。
ScraperConfiguration config;
long startTime = 0L;
try {
config = new ScraperConfiguration(
"H:\\workspace\\nutch\\src\\com\\jsq\\nutch\\jianjie.xml");
Scraper scraper = new Scraper(config, "E:\\tmp");// 指定工作目录,爬去后的xml会保存到这里
scraper.setDebug(true);
scraper.execute();
startTime = System.currentTimeMillis();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}