python 用于 PHP 的 Mechanize 和 BeautifulSoup?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1263800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mechanize and BeautifulSoup for PHP?
提问by Alix Axel
I was wondering if there was anything similar like Mechanize or BeautifulSoup for PHP?
我想知道是否有类似 Mechanize 或 BeautifulSoup for PHP 之类的东西?
采纳答案by Jon
SimpleTest provides you with similar functionality:
SimpleTest 为您提供了类似的功能:
回答by Pascal MARTIN
I don't know how powerful BeautifulSoup is, so maybe this won't be as great ; but you could try using DOMDocument::loadHTML
:
我不知道 BeautifulSoup 有多强大,所以也许这不会那么好;但你可以尝试使用DOMDocument::loadHTML
:
The function parses the HTML contained in the string source . Unlike loading XML, HTML does not have to be well-formed to load.
该函数解析包含在字符串 source 中的 HTML。与加载 XML 不同,HTML 无需格式良好即可加载。
After using this, you should be able to access the HTML document using DOM methods -- including XPath queries.
使用它之后,您应该能够使用 DOM 方法访问 HTML 文档——包括 XPath 查询。