百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
P

PHPScraper

> 开发工具
开源

一个适用于 PHP 的通用 Web 工具。

587 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个适用于 PHP 的通用 Web 工具。

For full documentation, visit phpscraper.de.

PHPScraper is a versatile web-utility for PHP. Its primary objective is to streamline the process of extracting information from websites, allowing you to focus on accomplishing tasks without getting caught up in the complexities of selectors, data structure preparation, and conversion.

Under the hood, it uses

  • BrowserKit (formerly Goutte) to access the web
  • League/URI to process URLs
  • donatello-za/rake-php-plus to extract and analyze keywords

See composer.json for more details.

:timer_clock: PHPScraper in 5 Minutes explained

Here are a few impressions of the way the library works. More examples are on the project website.

Basics: Flexible Calling as an Attribute or Method

All scraping functionality can be accessed either as a function call or a property call. For example, the title can be accessed in two ways:

php
// Prep
$web = new \Spekulatius\PHPScraper\PHPScraper;
$web->go('https://google.com');

// Returns "Google"
echo $web->title;

// Also returns "Google"
echo $web->title();

:battery: Batteries included: Meta data, Links, Images, Headings, Content, Keywords, ...

Many common use cases are covered already. You can find prepared extractors for various HTML tags, including interesting attributes. You can filter and combine these to your needs. In some cases there is an option to get a simple or detailed version, here in the case of linksWithDetails:

…

If there aren't any matching elements (here links) on the page, an empty array will be returned. If a method normally returns a string it might return null. Details such as follow_redirects, etc. are optional configuration parameters (see below).

Most of the DOM should be covered using these methods:

  • several meta-tags and other [``-information](https://phpscraper.de/examples/scrape-header-tags.html)
  • Social-Media information like Twitter Card and Facebook Open Graph
  • Content: Headings, Outline, Texts and Lists
  • Images
  • Links
  • Keywords

A full list of methods with example code can be found on phpscraper.de. Further examples are in the tests.

Download Files

Besides processing the content on the page itself, you can download files using fetchAsset:

php
// Absolute URL
$csvString = $web->fetchAsset('https://test-pages.phpscraper.de/test.csv');

// Relative URL after navigation
$csvString = $web
  ->go('https://test-pages.phpscraper.de/meta/lorem-ipsum.html')
  ->fetchAsset('/test.csv');

You will only need to write the content into a file or cloud storage.

Process the RSS feeds, sitemap.xml, etc.

PHPScraper can assist in collecting feeds such as RSS feeds, sitemap.xml-entries and static search indexes. This can be useful when deciding on the next page to crawl or building up a list of pages on a website.

Here we are processing the sitemap into a set of FeedEntry-DTOs:

php
(new \Spekulatius\PHPScraper\PHPScraper)
    ->go('https://phpscraper.de')
    ->sitemap

// array(131) {
//   [0]=>
//   object(Spekulatius\PHPScraper\DataTransferObjects\FeedEntry)#165 (3) {
//     ["title"]=>
//     string(0) ""
//     ["description"]=>
//     string(0) ""
//     ["link"]=>
//     string(22) "https://phpscraper.de/"
//   }
//   [1]=>
// ...

Whenever post-processing is applied, you can fall back to the underlying *Raw-methods.

Process CSV-, XML- and JSON files and URLs

PHPScraper comes out of the box with file / URL processing methods for CSV-, XML- and JSON:

  • parseJson
  • parseXml
  • parseCsv
  • parseCsvWithHeader (generates an asso. array using the first row)

Each method can process both strings as well as URLs:

…

Additional CSV parsing parameters such as separator, enclosure and escape are possible.

There is more!

There are plenty of examples on the PHPScraper website and in the tests.

Check the playground.php if you prefer learning by doing. You get it up and running with:

bash
$ git clone [email protected]:spekulatius/PHPScraper.git && composer update

:muscle: Roadmap

The future development is organized into milestones. Releases follow semver.

v1: Building the first stable version

  • Improve documentation and examples.
  • Organize code better (move websites into separate repos, etc.)
  • Add support for feeds and some typical file types.

v2: Service Upgrade:

  • Switch from Goutte to Symfony BrowserKit. Goutte has been archived.

v3: Expand the functionality and cover more 'types'

  • Expand to parse a wider range of types, elements, embeds, etc.
  • Improve performance with caching and concurrent fetching of assets
  • Minor improvements for parsing methods

v4: Expand to provide more guidance on building custom scrapers on top of PHPScraper

TBC.

:heart_eyes: Sponsors

PHPScraper is sponsored by:

With your support, PHPScraper can became the PHP swiss army knife for the web. If you find PHPScraper useful to your work, please consider a sponsorship or donation. Thank you :muscle:

:gear: Configuration (optional)

If needed, you can use the following configuration options:

User Agent

You can set the browser agent using setConfig:

php
$web->setConfig([
  'agent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0'
]);

It defaults to Mozilla/5.0 (compatible; PHP Scraper/1.x; +https://phpscraper.de).

Proxy Support

You can configure proxy support with setConfig:

php
$web->setConfig(['proxy' => 'http://user:[email protected]:3128']);

Timeout

You can set the timeout using setConfig:

php
$web->setConfig(['timeout' => 15]);

Setting the timeout to zero will disable it.

Disabling SSL

While unrecommended, it might be required to disable SSL checks. You can do so using:

php
$web->setConfig(['disable_ssl' => true]);

You can call setConfig multiple times. Each call merges the given config with the defaults again, not with the config from a previous call — so any custom values from an earlier call that you don't repeat will be reset to their defaults.

:rocket: Installation with Composer

bash
composer require spekulatius/phpscraper

After the installation, the package will be picked up by the Composer autoloader. If you are using a common PHP application or framework such as Laravel or Symfony you can start scraping now :rocket:

If not or you are building a standalone-scraper, please include the autoloader in vendor/ at the top of your file:

php
<?php

require __DIR__ . '/vendor/autoload.php';

// ...

Now you can now use any of the examples on the documentation website or from the tests/-folder.

Please consider supporting PHPScraper with a star or sponsorship:

bash
composer thanks

Thank you :muscle:

:white_check_mark: Testing

The library comes with a PHPUnit test suite. To run the tests, run the following command from the project folder:

bash
composer test

You can find the tests here. The test pages are publicly available.

MISC: Issues, Ideas, Contributing, CHANGELOG, UPGRADING, LICENSE

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPbeautifulsoupchromiumheadless-chromephp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具