Java網絡爬蟲:kamike.collect
Another Simple Crawler 又一個網絡爬蟲,可以支持代理服務器的KX上網爬取。
1.數據存在mysql當中。
2.使用時,先修改web-inf/config.ini的數據鏈接相關信息,主要是數據庫名和用戶名和密碼
3.然后訪問http://127.0.0.1/fetch/install 鏈接,自動創建數據庫表
4.修改src\java\cn\exinhua\fetch中的RestServlet.java文件:
FetchInst.getInstance().running=true; Fetch fetch = new Fetch(); fetch.setUrl("http://www.washingtonpost.com/"); fetch.setDepth(3); RegexRule regexRule = new RegexRule(); regexRule.addNegative(".*#.*"); regexRule.addNegative(".*png.*"); regexRule.addNegative(".*jpg.*"); regexRule.addNegative(".*gif.*"); regexRule.addNegative(".*js.*"); regexRule.addNegative(".*css.*"); regexRule.addPositive(".*php.*"); regexRule.addPositive(".*html.*"); regexRule.addPositive(".*htm.*"); Fetcher fetcher = new Fetcher(fetch); fetcher.setProxyAuth(true); fetcher.setRegexRule(regexRule); List<Fetcher> fetchers = new ArrayList<>(); fetchers.add(fetcher); FetchUtils.start(fetchers); 將其配置為需要的參數,然后訪問http://127.0.0.1/fetch/fetch啟動爬取 代理的配置在Fetch.java文件中: protected int status; protected boolean resumable = false; protected RegexRule regexRule = new RegexRule(); protected ArrayList<String> seeds = new ArrayList<String>(); protected Fetch fetch; protected String proxyUrl="127.0.0.1"; protected int proxyPort=4444; protected String proxyUsername="hkg"; protected String proxyPassword="dennis"; protected boolean proxyAuth=false;
5.訪問http://127.0.0.1/fetch/suspend可以停止爬取
本文由用戶 yne7 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!