Recently need to crawl to some of the site's products, began to find methods on the Internet, originally wanted to do with Python, because previously written in Python a small script, crawling a literature site free literature.
The step is like this: 1, first get the HTML file of the given URL, and then in this file with regular expressions to match the desired URL (may contain paging URL), and then get the matching URL of the HTML, in these HTML files there will be downloadable PDF file links, These links are then saved to disk. (This is because the site has anti-crawler, so the middle of the time spent in the simulation browser). After the link is downloaded, a shell script is written, each time a link is downloaded, and then saved to the specified folder.
This demand is different from the previous requirements, the need to crawl some of the target site's information, a bit more complicated than last time. It took two days to find several frameworks on the web and finally decided to use the WebMagic Java-based framework.
This framework is also chosen because it is convenient, easy to develop two times, and integrates some other tools, such as extracting elements from specified HTML tags.
WebMagic four main components: 1,downloader;2,pageprocessor;3,scheduler;4,pipeline.
Downloader is responsible for downloading the page from the Web, Pageprocessor is responsible for parsing the page, extracting useful information, discovering links, scheduler managing the crawled URLs and deduplication, pipeline is the storage and display of data, you can print to the console, Output to a local file or write to a database.
The webmagic of these components have been implemented, and users simply need to design their own rules for extracting content.
Attached link https://github.com/code4craft/webmagic
Java Crawler Framework WebMagic