Java 使用Web harvest抓取网页内容
我想从网页中刮取特定内容,为此我使用WebHarvest。当我试图刮取内容时,它在其他网站上工作得很好,但它不能刮取其他网站的内容 我的Java代码如下:Java 使用Web harvest抓取网页内容,java,html,web-scraping,webharvest,Java,Html,Web Scraping,Webharvest,我想从网页中刮取特定内容,为此我使用WebHarvest。当我试图刮取内容时,它在其他网站上工作得很好,但它不能刮取其他网站的内容 我的Java代码如下: import org.webharvest.definition.ScraperConfiguration; import org.webharvest.runtime.Scraper; import org.webharvest.runtime.variables.Variable; import java.io.FileNotFoundE
import org.webharvest.definition.ScraperConfiguration;
import org.webharvest.runtime.Scraper;
import org.webharvest.runtime.variables.Variable;
import java.io.FileNotFoundException;
public class App
{
public static void main(String[] args)
{
try
{
ScraperConfiguration config = new ScraperConfiguration("twit88.xml");
Scraper scraper = new Scraper(config, "c:/temp/");
//scraper.getHttpClientManager().setHttpProxy("proxy-server", 8001);
scraper.addVariableToContext("url", "http://freesearch.naukri.com/preview/preview?uname=63017692f2b266780bfd20476cd67466001a4a17005b4a5355041f121b502e18514b4e4e43121c4151005&sid=73682841<=1339495252");
scraper.setDebug(true);
scraper.execute();
// takes variable created during execution
Variable article = (Variable)scraper.getContext().getVar("article");
// do something with articles...
System.out.println(article.toString());
//System.out.println("1234=====rtyu");
}
catch (FileNotFoundException e)
{
System.out.println(e.getMessage());
}
}
}
我的XML在这里:
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<!--
<var-def name="url">http://twit88.com/blog/2008/01/02/java-encrypt-and-send-a- large-file-securely/</var-def>
-->
<!-- <file action="write" path="twit88/twit88${sys.date()}.xml" charset="UTF-8"> -->
<!--
<template>
<![CDATA[ <twit88 date="${sys.datetime("dd.MM.yyyy")}"> ]]>
</template>
-->
<var-def name="article">
<xquery>
<xq-param name="doc">
<html-to-xml outputtype="browser-compact" prunetags="yes">
<http url="${url}"/>
</html-to-xml>
</xq-param>
<xq-expression><![CDATA[
declare variable $doc as node() external;
let $title := data($doc//div[@class="bdrGry"]/div[@class="boxHD1"]/h1)
return
<article>
<title>{data($title)}</title>
</article>
]]>
</xq-expression>
</xquery>
</var-def>
<!--
<![CDATA[ </twit88> ]]> -->
<!-- </file> -->
</config>
但它不起作用。谁能告诉我我做错了什么
..它不是为你刮东西
来自Naukri.com的网址:
Naukri.com使用技术手段将机器人等排除在网站抓取和内容抓取之外。用户承诺不会绕过这些方法。
..它不是为你刮东西
来自Naukri.com的网址:
Naukri.com使用技术手段将机器人等排除在网站抓取和内容抓取之外。用户承诺不会绕过这些方法。
另一方面,它是“刮”或“刮”,而不是“刮”或“刮”。您可能已经从上面看到的代码中得到了一些提示。谢谢您纠正我的错误。但是解决这个问题的方法是什么?拼写?编辑(我已经完成了)。另外,它是“scrape”或“scraping”,而不是“scraps”或“scraping”。您可能已经从上面看到的代码中得到了一些提示。谢谢您纠正我的错误。但是解决这个问题的方法是什么?拼写?编辑(我已经完成了)。而且今后在打字问题上要更加注意/谨慎。
declare variable $doc as node() external;
let $title := data($doc//div[@class="bdrGry"]/div[@class="boxHD1"]/h1)