ngfw/webparser 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ngfw/webparser

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ngfw/webparser

包简介

WebParser is a PHP library that allows developers to parse and query webpages using an ORM-like syntax. It facilitates the extraction of HTML elements by chaining operations such as filtering by ID or class, ordering results, and limiting output. WebParser offers a flexible interface for exploring a

README 文档

README

Latest Version on Packagist Total Downloads

WebParser is an ORM-style web scraping package for Laravel, designed to make DOM parsing simple and intuitive. With a fluent, chainable API, WebParser lets you effortlessly navigate, select, and extract data from HTML documents, bringing the ease of database querying to web scraping.

Installation

You can install the package via composer:

composer require ngfw/webparser

Usage

Here's how you can start using WebParser:

use Ngfw\Webparser\Facades\WebParser;


// Initialize WebParser with a URL
$webParser = WebParser::fromUrl('https://laravel.com/');

// Extract the page title
$pageTitle = $webParser->select('text')->where('title')->first();
echo $pageTitle;

// Extract the content of the meta description
$metaDescription = $webParser->whereAttribute('name', 'description')->pluck('content')->first();
echo $metaDescription;

// Extract the first H1 tag's text content
$firstH1 = $webParser->select('text')->where('h1')->first();
echo $firstH1;

// Find an H2 element within a complex class structure and extract its text
$complexH2 = $webParser->where('.relative .max-w-screen-xl .w-full .mx-auto .xl:px-5')->find('h2')->select('text')->first();
echo $complexH2;

// Extract the text from all H2 tags on the page
$allH2Texts = $webParser->select('text')->where('h2')->get();
print_r($allH2Texts);

// Extract the sources (src) of all images on the page
$imageSources = $webParser->where('img')->pluck('src')->all();
print_r($imageSources);

Testing

To run the tests, use:

vendor/bin/phpunit

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email the author instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Hire Me

Looking for a Laravel expert to help with your next project? I'm available for freelance work! Feel free to contact me to discuss how I can assist you.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-08-22