tojibon / web-scraper
使用PHP cURL抓取网页的PHP类。通过它,您可以使用cURL的GET或POST方法抓取网页,也可以通过表单POST方法从基于asp.net的网站抓取网页内容。
1.1
2017-01-06 10:10 UTC
Requires
- php: ^5.5 || ^7.0
This package is not auto-updated.
Last update: 2024-09-28 20:03:43 UTC
README
- 一个非常简单的单页PHP爬虫类,利用cURL库抓取网页内容。可以使用GET或POST方法抓取网页,也可以使用表单POST方法从基于asp.net的网站抓取网页内容。
- 支持
- GET方法
- POST方法
- ASP调用
- 通过标记标签名称检索页面内容
- 从表单字段中检索值
安装
composer require juyal-ahmed/web-scraper
获取完整网页内容
<?php require 'vendor/autoload.php'; // Create a Scraper instance with only the URL specified $scraper = new \PhpFarmer\WebScraper\Scraper('https://example.com'); $pageHtmlContent = $scraper->getPageContent('https://example.com/page.html'); ?>
获取完整网页内容
<?php require 'vendor/autoload.php'; // Create a Scraper instance with custom cache settings $scraperWithCache = new Scraper('https://example.com', true, './custom_cache/', 600); $pageHtmlContent = $scraper->getPageContent('https://example.com/page.html'); ?>
使用代理IP获取完整网页内容
<?php require 'vendor/autoload.php'; // Create a Scraper instance with only the URL specified $scraper = new \PhpFarmer\WebScraper\Scraper('https://example.com'); $pageHtmlContent = $scraper->curl('https://example.com/page.html', "93.118.xx.141:8800", "6USERR:8PASS1"); ?>
解析页面HTML内容
<?php $subHtmlContent = $scraper->getHtmlContentBetweenTags($pageHtmlContent, '', ''); ?>
工作原理
- 在您的页面头部包含scraper.php类。
- 设置一些默认设置。
- 通过其现有方法获取页面内容。
- 如果需要单条内容,使用getHtmlContentBetweenTags方法分割内容。
- 如果需要网格数据,使用针(例如explode())分割内容。
- 然后遍历整个内容,再次使用getHtmlContentBetweenTags获取内容,以创建网格数据的最终数组。
- 就这样
谢谢