dataflowkitvsphpscraper
Dataflow kit ("DFK") is a Web Scraping framework for Gophers. It extracts data from web pages, following the specified CSS Selectors. You can use it in many ways for data mining, data processing or archiving.
Web-scraping pipeline consists of 3 general components:
- Downloading an HTML web-page. (Fetch Service)
- Parsing an HTML page and retrieving data we're interested in (Parse Service)
- Encoding parsed data to CSV, MS Excel, JSON, JSON Lines or XML format.
For fetching dataflowkit has several types of page fetchers:
- Base fetcher uses standard golang http client to fetch pages as is. It works faster than Chrome fetcher. But Base fetcher cannot render dynamic javascript driven web pages.
- Chrome fetcher is intended for rendering dynamic javascript based content. It sends requests to Chrome running in headless mode.
For parsing dataflowkit extracts data from downloaded web page following the rules listed in configuration JSON file. Extracted data is returned in CSV, MS Excel, JSON or XML format.
Some dataflowkit features:
- Scraping of JavaScript generated pages;
- Data extraction from paginated websites;
- Processing infinite scrolled pages.
- Sсraping of websites behind login form;
- Cookies and sessions handling;
- Following links and detailed pages processing;
- Managing delays between requests per domain;
- Following robots.txt directives;
- Saving intermediate data in Diskv or Mongodb. Storage interface is flexible enough to add more storage types easily;
- Encode results to CSV, MS Excel, JSON(Lines), XML formats;
- Dataflow kit is fast. It takes about 4-6 seconds to fetch and then parse 50 pages.
- Dataflow kit is suitable to process quite large volumes of data. Our tests show the time needed to parse appr. 4 millions of pages is about 7 hours.
PHPScraper is a universal web-util for PHP. The main goal is to get stuff done instead of getting distracted with selectors, preparing & converting data structures, etc. Instead, you can just go to a website and get the relevant information for your project.
PHPScraper is a minimalistic scraper framework that is built on top of other popular scraping tools.
Features:
- Direct access to page basic features like: Meta data, Links, Images, Headings, Content, Keywords etc.
- File downloading.
- RSS, Sitemap and other feed processing.
- CSV, XML and JSON file processing.
Example Use
{
"name": "collection",
"request": {
"url": "https://example.com"
},
"fields": [
{
"name": "Title",
"selector": ".product-container a",
"extractor": {
"types": [
"text",
"href"
],
"filters": [
"trim",
"lowerCase"
],
"params": {
"includeIfEmpty": false
}
}
},
{
"name": "Image",
"selector": "#product-container img",
"extractor": {
"types": [
"alt",
"src",
"width",
"height"
],
"filters": [
"trim",
"upperCase"
]
}
},
{
"name": "Buyinfo",
"selector": ".buy-info",
"extractor": {
"types": [
"text"
],
"params": {
"includeIfEmpty": false
}
}
}
],
"paginator": {
"selector": ".next",
"attr": "href",
"maxPages": 3
},
"format": "json",
"fetcherType": "chrome",
"paginateResults": false
}
// create scraper object
$web = new \Spekulatius\PHPScraper\PHPScraper;
// go to URL
$web->go('https://test-pages.phpscraper.de/content/selectors.html');
// elements can be found using XPath:
echo $web->filter("//*[@id='by-id']")->text(); // "Content by ID"
// or pre-defined variables covering basic page data:
$web->links; // for all links
$web->headings;
$web->images;
$web->contentKeywords;
$web->orderedLists;
$web->unorderedLists;
$web->paragraphs;
$web->outline; // basic page outline
$web->cleanOutlineWithParagraphs; // basic page outline