- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用curl 从维基百科检索信息。到目前为止,我已经成功检索了基本文本信息,但我真的想以 HTML 形式检索它。
这是我的代码:
$s = curl_init();
$url = 'http://boss.yahooapis.com/ysearch/web/v1/site:en.wikipedia.org+'.$article_name.'?appid=myID';
curl_setopt($s,CURLOPT_URL, $url);
curl_setopt($s,CURLOPT_HEADER,false);
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);
$rs = curl_exec($s);
$rs = Zend_Json::decode($rs);
$rs = ($rs['ysearchresponse']['resultset_web']);
$rs = array_shift($rs);
$article= str_replace('http://en.wikipedia.org/wiki/', '', $rs['url']);
$url = 'http://en.wikipedia.org/w/api.php?';
$url.='format=json';
$url.=sprintf('&action=query&titles=%s&rvprop=content&prop=revisions&redirects=1', $article);
curl_setopt($s,CURLOPT_URL, $url);
curl_setopt($s,CURLOPT_HEADER,false);
curl_setopt($s,CURLOPT_RETURNTRANSFER,1);
$rs = curl_exec($s);
//curl_close( $s );
$rs = Zend_Json::decode($rs);
$rs = array_pop(array_pop(array_pop($rs)));
$rs = array_shift($rs['revisions']);
$articleText = $rs['*'];
但是,以这种方式检索到的文本不足以显示:(都是这种格式
'''Aix-les-Bains''' is a [[Communes of France|commune]] in the [[Savoie]] [[Departments of France|department]] in the [[Rhône-Alpes]] [[regions of France|region]] in southeastern [[France]].
It lies near the [[Lac du Bourget]], {{convert|9|km|mi|abbr=on}} by rail north of [[Chambéry]].
==History== ''Aix'' derives from [[Latin]] ''Aquae'' (literally, "waters"; ''cf'' [[Aix-la-Chapelle]] (Aachen) or [[Aix-en-Provence]]), and Aix was a bath during the [[Roman Empire]], even before it was renamed ''Aquae Gratianae'' to commemorate the [[Emperor Gratian]], who was assassinated not far away, in [[Lyon]], in [[383]]. Numerous Roman remains survive. [[Image:IMG 0109 Lake Promenade.jpg|thumb|left|Lac du Bourget Promenade]]
如何获取维基百科文章的 HTML?
更新:谢谢,但我对此有点陌生,现在我正在尝试运行 xpath 查询[尽管是第一次],但似乎无法获得任何结果。我实际上需要知道一些事情。
我经历过这个url关于维基百科的数据挖掘 - 它提出了一个想法,以检索到的维基百科文本作为参数向维基百科 api 发出第二个请求,这将检索 html - 尽管到目前为止它似乎还没有工作:( - 我不想要只需将整篇文章作为一堆 html 抓取并转储它。基本上我的应用程序的作用是在 map 上指定一些位置和城市 - 您单击城市标记,它会通过 ajax 请求详细信息城市要显示在相邻的 div 中。我希望动态地从维基百科获取此信息。我会担心稍后处理特定城市不存在的文章,只需要确保其此时正常工作。
有谁知道一个很好的工作示例可以实现我正在寻找的功能,即阅读和解析维基百科文章的选定部分。
根据提供的 url - 它说我应该将 wikitext 发布到 wikipedia api 位置,以便它返回解析后的 html。问题是,如果我发布信息,我不会得到任何响应,而是收到拒绝访问的错误 - 但是,如果我尝试将 wiki 文本包含为 GET,它的解析不会出现任何问题。但当我有太多文本需要解析时,它当然会失败。
这是维基百科 API 的问题吗?因为我已经破解了两天了,但一点运气都没有:(
最佳答案
最简单的解决方案可能是抓取页面本身(例如 http://en.wikipedia.org/wiki/Combination ),然后提取 <div id="content">
的内容,可能带有 xpath 查询。
关于php - 从 Wikipedia 获取信息 - 如何获取 HTML 表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/853450/
我正在尝试在维基百科上找到所有图像的完整列表,然后我可以将其过滤到公共(public)领域的图像。我已经从这里下载了 SQL 转储: http://dumps.wikimedia.org/enwiki
我正在学习使用 rasa 语言。为了使目标的答案多样化,我决定使用 Wikipedia api。为了创建我的工作环境,我使用带有以下命令的 anaconda: conda create --name
本页:http://wikidata.dbpedia.org/downloads/20160111/ 有一个名为 wikidatawiki-20160111-page-ids.ttl.bz2 的转储
这个问题已经有答案了: How to get the Infobox data from Wikipedia? (8 个回答) 已关闭 3 年前。 维基百科文章可能有信息框模板。通过以下调用,我可以获
我正在使用 Wikipedia API,在其中获取我输入的某些字符串的图像。 它总是返回 10 个结果,但我想要超过大约 50 个。 https://en.wikipedia.org/w/api.ph
我需要从 jquery(首选)或 php 数组中的特定维基百科文章获取“外部链接”链接。我已经浏览了维基百科 api,但似乎没有办法做到这一点。看起来 dbpedia 有一种方法可以做到这一点(dbp
我想在 python 程序中访问给定文章标题的维基百科信息框图像。有人可以告诉我如何获得吗? 以下截图提供了页面中所有图像的列表。我只想访问信息框图像。我该怎么做? import wikipedia
给定维基百科上的任何页面,例如 Coffee 的页面,我试图弄清楚如何提取页面上所有引用(包括任何元数据)的列表。乍一看,这似乎很容易,因为大多数页面都将它们全部列在称为“引用”的部分下。但是,当您检
我想计算特定语言的 wiki 转储中的实体/类别,比如英语。对于初学者来说,很难找到/遵循官方文档。到目前为止我所了解的是我可以下载一个 XML 转储(我从所有可用的不同文件中下载什么),并解析它(?
是否有任何 API 可以使用该页面的标题或页面 ID 或 url 获取页面的所有类别?我尝试在网上搜索,但我能找到的只是获取特定类别的转储。任何形式的帮助将不胜感激。 谢谢 最佳答案 您正在寻找的 A
Closed. This question is off-topic。它当前不接受答案。 想要改善这个问题吗? Update the question,所以它是用于堆栈溢出的on-topic。 9年前
我正在尝试构建维基百科文章及其类别的树形图。我需要做什么? 从这个站点(http://dumps.wikimedia.org/enwiki/latest/),我下载了: enwiki-latest-p
我使用 Wikipedia API 检索给定类别的页面列表。然而,页面由它们的 page_id 表示。如何使用 Wikipedia API 通过 page_id 获取页面的实际文本内容 最佳答案 AF
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
以这个Freebase查询为例,如何使用Wikidata API运行相同的查询? [{ "id": null, "name": null, "type": "/film/film",
有没有一种方法可以使用 MediaWiki API 或任何其他工具自动检索使用大概日期的维基百科文章的先前版本(不知道 'oldid' 值)? 例如,我如何检索 history version of
从Wikipedia获取有关人员的所有文章的最简单方法是什么?我知道我可以下载所有页面的转储,但是然后如何过滤这些页面并仅获取有关人员的页面?我需要尽可能多的东西(最好超过一百万),因此使用任何一种A
有这个花哨的infobox在 中。如何获得 的值? 最佳答案 错误的方法:尝试解析 HTML Use (cURL/jQuery/file_get_contents/requests/wget/mor
我需要检索某个 wiki 项目的所有现有语言的列表。例如,所有 Wikivoyage或全部Wikipedia语言,就像他们的登陆页面一样。 如果可能的话,我更喜欢通过 MediaWiki API 来完
我需要访问非常旧的法语维基百科转储(维基百科的备份)。我成功地从 archive.org 找到了 2010 年的备份,现在我正在搜索 2006 年甚至更早的版本。我知道在最新的转储中包含以前的所有数据
我是一名优秀的程序员,十分优秀!