我希望能够爬取几个博客并以编程方式分析它们基于HTML和CSS的布局,例如侧边栏是否在主内容左侧或右侧,有多少列以及它们有多宽。
最佳方法是什么?是否有任何工具或库可用?
(我更喜欢使用Python或PHP解决方案。)
最佳方法是什么?是否有任何工具或库可用?
(我更喜欢使用Python或PHP解决方案。)
看起来可以通过 PhantomJS 实现,使用类似这样的 Javascript 代码:
phantom.viewportSize = { width: 1024, height: 768 };
var page = new WebPage();
page.open("http://mashable.com/", function(status) {
if (status === "success")
{
page.includeJs("https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js", function() {
var position = page.evaluate(function() {
return jQuery('#sidebar').position();
});
// Now position.left and position.top contains the
// position of the #sidebar element. Use other
// jQuery functions to calculate the relative position.
phantom.exit();
});
}
});
你是在寻找这个吗?
这是在Google搜索中的第一个结果。还有至少其他四个看起来很有希望。也许你应该试试Google,列出你找到的内容,并针对特定的软件包寻求具体建议。