有人可以帮我吗我想从 http://www.quranexplorer.com/Hadith/English/Index.html 中提取 html 数据。我找到了一项完全可以做到这一点的服务 http://diffbot.com/dev/docs/它们支持通过简单的 api 提取数据,问题是我有大量需要处理的 url。链接如下 http://test.deen-ul-islam.org/html/h.js
我需要创建一个跟随 url 的脚本,然后使用 api 生成 html 数据的 json 格式(该网站的 api 允许批量请求检查网站文档)
请注意 diffbot 每月仅允许 10000 个免费请求,因此我需要一种方法来保存进度并能够从上次中断的地方继续。
这是我使用 php 创建的示例。
$token = "dfoidjhku";// example token
$url = "http://www.quranexplorer.com/Hadith/English/Hadith/bukhari/001.001.006.html";
$geturl="http://www.diffbot.com/api/article?tags=1&token=".$token."&url=".$url;
$json = file_get_contents($geturl);
$data = json_decode($json, TRUE);
echo $article_title=$data['title'];
echo $article_author=$data['author'];
echo $article_date=$data['date'];
echo nl2br($article_text=$data['text']);
$article_tags=$data['tags'];
foreach($article_tags as $result) {
echo $result, '<br>';
}
我不介意该工具是 javascript 还是 php,我只需要一种方法来获取 json 格式的 html 数据。
最佳答案
来自 Diffbot 的约翰在这里。注意:不是开发人员,但知道足以编写 hacky 代码来完成简单的事情。
您有一个链接列表 - 应该可以直接遍历这些链接,为每个链接调用我们。
这是执行此操作的 Python 脚本:https://gist.github.com/johndavi/5545375
我在 Sublime Text 中使用了快速搜索正则表达式从 JS 文件中提取链接。
要截断此内容,只需删除一些链接,然后运行它即可。由于我没有使用 Batch API,因此需要一段时间。
如果您需要改进或改变这一点,最好直接寻找更强大的开发人员。 Diffbot 是一个开发友好的工具。
关于php - 使用 Diffbot 提取 HTML 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16427094/