php - 在 PHP 中解析和处理 HTML:使用刮刀获取 Wordpress-plugin-Metadata
问题描述
如何在 PHP 中解析和处理 HTML - 一个简单的爬虫
我目前正在开发一个解析器,以便从用户在 PHP 中给出的 URL 对页面进行小预览。
我想只检索页面的标题和一小部分信息(一些文本)
该项目:获取流行的 wordpress 插件的元数据列表(参见https://de.wordpress.org/plugins/browse/popular/并收集前 50 个 URL - 这是 50 个感兴趣的插件!挑战是:我想获取所有现有插件的元数据。我随后想要在获取后过滤掉的是 - 那些具有最新时间戳的插件 - 最近更新(最近)。这一切都是...
https://wordpress.org/plugins/wp-job-manager
https://wordpress.org/plugins/ninja-forms
https://wordpress.org/plugins/participants-database ....and so on and so forth.
所以要考虑一页 - 获取一个 Wordpress 插件的元数据:使用 simple_html_dom (http://simplehtmldom.sourceforge.net/)我想有一种适当的方式和方法可以在没有任何其他外部的情况下做到这一点库/类。到目前为止,我还尝试使用一般(DOM)-DOCDocument 类http://docs.php.net/manual/en/domdocument.loadhtml.php),加载 HTML 并将其显示在屏幕上,现在我思考正确的方法来做到这一点。我为此考虑 simple_html_dom ( http://simplehtmldom.sourceforge.net/ )。这将使它变得非常容易。这是一个如何提取标题和元文本(描述)的示例。
<?php
require 'simple_html_dom.php';
$html = file_get_html('https://wordpress.org/plugins/wp-job-manager/');
$title = $html->find ("h1", class_="plugin-title").text];
$text = $html->find(class_="entry-meta").text];
echo $title->plaintext."<br>\n";
echo $texte->text;
?>
查看源代码:https ://wordpress.org/plugins/wp-job-manager/ 我们为每个 wordpress-plugin 提供以下元数据集:
Version: 1.9.5.12
installations: 10,000+
WordPress Version: 5.0 or higher
Tested up to: 5.4 PHP
Version: 5.6 or higher
Tags 3 Tags: database member sign-up form volunteer
Last updated: 19 hours ago
plugin-ratings
该项目由两部分组成:循环部分:循环访问此 URL https://de.wordpress.org/plugins/browse/popular/并收集大约 50 到 80 个 URL(这似乎很简单)。解析器部分:我有一些问题 - 正确获取标签和插件评级的数据......
更新:插件 api。可以在这里提供帮助 - 一个很好的方法是 cf Getting a list of ALL plugins
解决方案
推荐阅读
- spring-webflux - 通过映射到新的返回值来处理 Reactor 错误而不删除任何元素
- nuxt.js - 如何在 Nuxt 的站点地图中包含完整的动态路线
- php - 如何在我的评论打印系统中添加准备语句
- azure - 无法运行 Azure 表单识别器布局_遇到意外的元素引用
- java - 使用 Azure Key Vault 中的证书进行 MTL 通信
- lua - 杀死NPC时如何得分
- django - AUTH_USER_MODEL 指的是尚未安装的模型“users.CustomUser”
- mysql - 为 Mysql 存储过程使用 Controller Laravel 8 变量值
- python - Numpy/pandas___如何撤消数组?
- javascript - TypeError: setTimeout(...).unref 不是函数