PHP 中的 HTML 抓取

发布于 2024-07-04 02:45:01 字数 104 浏览 6 评论 0原文

我一直在使用正则表达式在 PHP 中进行一些 HTML 抓取。 这可行,但结果是挑剔且脆弱的。 有没有人使用过任何提供更强大解决方案的软件包? 配置驱动的解决方案将是理想的,但我并不挑剔。

I've been doing some HTML scraping in PHP using regular expressions. This works, but the result is finicky and fragile. Has anyone used any packages that provide a more robust solution? A config driven solution would be ideal, but I'm not picky.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

梦毁影碎の 2024-07-11 02:45:01

从页面中抓取 HTML 后,我会推荐 PHP Simple HTML DOM Parser 。 它支持无效的 HTML,并提供了一种非常简单的方法来处理 HTML 元素。

I would recomend PHP Simple HTML DOM Parser after you have scraped the HTML from the page. It supports invalid HTML, and provides a very easy way to handle HTML elements.

街道布景 2024-07-11 02:45:01

如果您正在抓取的页面是有效的 X(HT)ML,则任何 PHP 的内置的 XML 解析器 就可以了。

我在使用 PHP 库进行抓取方面还没有取得太大成功。 如果您喜欢冒险,可以尝试 simplehtmldom。 我建议 Ruby 使用 HpricotBeautiful Soup for Python,它们都是优秀的 HTML 解析器。

If the page you're scraping is valid X(HT)ML, then any of PHP's built-in XML parsers will do.

I haven't had much success with PHP libraries for scraping. If you're adventurous though, you can try simplehtmldom. I'd recommend Hpricot for Ruby or Beautiful Soup for Python, which are both excellent parsers for HTML.

别挽留 2024-07-11 02:45:01

我还推荐“简单的 HTML DOM 解析器”。 这是一个不错的选择,特别是如果您熟悉 jQuery 或 JavaScript 选择器,那么您会发现自己宾至如归。

我什至在博客中介绍过它过去。

I would also recommend 'Simple HTML DOM Parser.' It is a good option particularly if your familiar with jQuery or JavaScript selectors then you will find yourself at home.

I have even blogged about it in the past.

梦罢 2024-07-11 02:45:01

我使用 htmlSQL 获得了一些乐趣,这并不是一个高端解决方案,但非常简单与. 一起工作。

I had some fun working with htmlSQL, which is not so much a high end solution, but really simple to work with.

止于盛夏 2024-07-11 02:45:01

使用 PHP 进行 HTML 抓取,我建议使用 cURL + regexp 或 cURL + 一些 DOM 解析器,尽管我个人使用 cURL + regexp。 如果您对正则表达式有深入的了解,有时它实际上会更准确。

Using PHP for HTML scraping, I'd recommend cURL + regexp or cURL + some DOM parsers though I personally use cURL + regexp. If you have a profound taste of regexp, it's actually more accurate sometimes.

念﹏祤嫣 2024-07-11 02:45:01

我使用上面提到的 Simple Html DOM Parser 也得到了很好的结果。 然后还有 tidy PHP 扩展,它也运行得很好。

I've had very good with results with the Simple Html DOM Parser mentioned above as well. And then there's the  tidy Extension for PHP as well which works really well too.

纵山崖 2024-07-11 02:45:01

我必须在主机 1 和 1 上使用curl。

http://www.quickscrape.com/ 是我使用 Simple DOM 类想出的!

I had to use curl on my host 1and1.

http://www.quickscrape.com/ is what I came up with using the Simple DOM class!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文