- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是 this 的后续问题问题。
同样的想法:我从 PubMed 中提取 XML 数据,并使用curl 来处理这些结果。这使我能够获取所需的信息(酒吧 ID 列表)并将其用作另一个 PubMed 抓取的变量。 $name 最终将是动态的。
<?php
$name = 'white,theodore';
// Return xml data from PubMed based on author search name
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term='.$name.'[author]&retmode=xml&retmax=50');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
$output = curl_exec($ch);
curl_close($ch);
// Parse the results and concatenate into a string of Publication IDs
$xml=simplexml_load_string($output);
$idList = $xml->IdList;
$ids = "";
foreach($idList->children() as $id) {
$ids .= $id . ",";
}
// Plug that string of IDs into another PubMed search, this one returning XML data for Publication Summaries
$path = 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id='.$ids;
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, $path);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_VERBOSE, 0);
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch2, CURLOPT_AUTOREFERER, true);
curl_setopt($ch2, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch2, CURLOPT_FRESH_CONNECT, 1);
$data = curl_exec($ch2);
curl_close($ch2);
// Parse those results and print only what is needed for Citation format
$cxml=simplexml_load_string($data);
foreach($cxml->children() as $docsum) {
foreach($docsum->children() as $item) {
foreach($item->children() as $details) {
if ((string) $details['Name'] === 'Author') {echo $details . "., ";}
}
if ((string) $item['Name'] === 'FullJournalName') { echo $item . ". "; }
if ((string) $item['Name'] === 'Title') { echo "<strong>" . $item . "</strong> "; }
if ((string) $item['Name'] === 'Volume') { echo "Vol." . $item . ", "; }
if ((string) $item['Name'] === 'Issue') { echo "Issue" . $item . ". "; }
if ((string) $item['Name'] === 'PubDate') { echo $item . ". "; }
foreach($item->children() as $details) {
if ((string) $details['Name'] === 'PubType') {echo $details . ", ";}
}
}
echo "</br></br>";
}
?>
它返回以下 XML 数据(这是一个结果)。
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE eSummaryResult PUBLIC "-//NLM//DTD esummary v1 20041029//EN" "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20041029/esummary-v1.dtd">
<eSummaryResult>
<DocSum>
<Id>27431223</Id>
<Item Name="PubDate" Type="Date">2016 Oct</Item>
<Item Name="EPubDate" Type="Date">2016 Sep 23</Item>
<Item Name="Source" Type="String">Antimicrob Agents Chemother</Item>
<Item Name="AuthorList" Type="List">
<Item Name="Author" Type="String">Bhattacharya S</Item>
<Item Name="Author" Type="String">Sobel JD</Item>
<Item Name="Author" Type="String">White TC</Item>
</Item>
<Item Name="LastAuthor" Type="String">White TC</Item>
<Item Name="Title" Type="String">A Combination Fluorescence Assay Demonstrates Increased Efflux Pump Activity as a Resistance Mechanism in Azole-Resistant Vaginal Candida albicans Isolates.</Item>
<Item Name="Volume" Type="String">60</Item>
<Item Name="Issue" Type="String">10</Item>
<Item Name="Pages" Type="String">5858-66</Item>
<Item Name="LangList" Type="List">
<Item Name="Lang" Type="String">English</Item>
</Item>
<Item Name="NlmUniqueID" Type="String">0315061</Item>
<Item Name="ISSN" Type="String">0066-4804</Item>
<Item Name="ESSN" Type="String">1098-6596</Item>
<Item Name="PubTypeList" Type="List">
<Item Name="PubType" Type="String">Journal Article</Item>
</Item>
<Item Name="RecordStatus" Type="String">Unknown status</Item>
<Item Name="PubStatus" Type="String">epublish</Item>
<Item Name="ArticleIds" Type="List">
<Item Name="pubmed" Type="String">27431223</Item>
<Item Name="pii" Type="String">AAC.01252-16</Item>
<Item Name="doi" Type="String">10.1128/AAC.01252-16</Item>
<Item Name="pmc" Type="String">PMC5038269</Item>
<Item Name="rid" Type="String">27431223</Item>
<Item Name="eid" Type="String">27431223</Item>
<Item Name="pmcid" Type="String">pmc-id: PMC5038269;embargo-date: 2017/04/01;</Item>
</Item>
<Item Name="DOI" Type="String">10.1128/AAC.01252-16</Item>
<Item Name="History" Type="List">
<Item Name="received" Type="Date">2016/06/10 00:00</Item>
<Item Name="accepted" Type="Date">2016/07/12 00:00</Item>
<Item Name="pmc-release" Type="Date">2017/04/01 00:00</Item>
<Item Name="entrez" Type="Date">2016/07/20 06:00</Item>
<Item Name="pubmed" Type="Date">2016/07/20 06:00</Item>
<Item Name="medline" Type="Date">2016/07/20 06:00</Item>
</Item>
<Item Name="References" Type="List"></Item>
<Item Name="HasAbstract" Type="Integer">1</Item>
<Item Name="PmcRefCount" Type="Integer">0</Item>
<Item Name="FullJournalName" Type="String">Antimicrobial agents and chemotherapy</Item>
<Item Name="ELocationID" Type="String">doi: 10.1128/AAC.01252-16</Item>
<Item Name="SO" Type="String">2016 Oct;60(10):5858-66</Item>
</DocSum>
</eSummaryResult>
</br></br>
这与此相呼应:
2016 Oct. Bhattacharya S., Sobel JD., White TC., A Combination Fluorescence Assay Demonstrates Increased Efflux Pump Activity as a Resistance Mechanism in Azole-Resistant Vaginal Candida albicans Isolates. Vol.60, Issue10. Journal Article, Antimicrobial agents and chemotherapy.
Zavrel M., White TC., Medically important fungi respond to azole drugs: an update. Vol.10, Issue8. Journal Article, Review, Future microbiology.
Esquivel BD., Smith AR., Zavrel M., White TC., Azole drug import into the pathogenic fungus Aspergillus fumigatus. Vol.59, Issue6. Journal Article, Antimicrobial agents and chemotherapy.
2015 Apr. Achterman RR., Moyes DL., Thavaraj S., Smith AR., Blair KM., White TC., Naglik JR., Dermatophytes activate skin keratinocytes via mitogen-activated protein kinase signaling and induce immune responses. Vol.83, Issue4. Journal Article, Infection and immunity.
2015 Feb 3. Ford CB., Funt JM., Abbey D., Issi L., Guiducci C., Martinez DA., Delorey T., Li BY., White TC., Cuomo C., Rao RP., Berman J., Thompson DA., Regev A., The evolution of drug resistance in clinical isolates of Candida albicans. Vol.4, Issue. Journal Article, eLife.
2014 Aug 1. White TC., Findley K., Dawson TL Jr., Scheynius A., Boekhout T., Cuomo CA., Xu J., Saunders CW., Fungi on the skin: dermatophytes and Malassezia. Vol.4, Issue8. Journal Article, Review, Cold Spring Harbor perspectives in medicine.
2014 Jan. Maguire SL., Wang C., Holland LM., Brunel F., Neuvéglise C., Nicaud JM., Zavrel M., White TC., Wolfe KH., Butler G., Zinc finger transcription factors displaced SREBP proteins as the major Sterol regulators during Saccharomycotina evolution. Vol.10, Issue1. Journal Article, PLoS genetics.
2013 Nov 15. Campoli P., Perlin DS., Kristof AS., White TC., Filler SG., Sheppard DC., Pharmacokinetics of posaconazole within epithelial cells and fungi: insights into potential mechanisms of action during treatment and prophylaxis. Vol.208, Issue10. Journal Article, The Journal of infectious diseases.
2013 Jul 8. Achterman RR., White TC., Dermatophytes. Vol.23, Issue13. Journal Article, Current biology : CB.
ETC.
一切都很好,并且仅使用我需要的数据生成引文,但我无法重新排序结果,因此作者排在第一位,PubDate 排在最后,等等。我尝试了多种选项,但我对任何选项都不够熟悉他们似乎无法破解它。
我已尝试附加 XSLT 样式表,但我认为这不起作用,因为我实际上并未输出 XML 文件。也许?
我尝试使用以下 XPath 而不是底部的 SimpleXML block 来返回引用,但仍然得到空白结果。因为所有数据都被标记为 <Item>
,我尝试使用 Name 属性失败。
$content = simplexml_load_string($data);
$results = $content->xpath('Item[@Name]');
foreach($results as $result) {
$title = $result->xpath('[@Name="Title"]');
// Make sure there's an author attribute
if($title) {
// because we have a list of elements even if there's one result
$items = $title[0]->attributes();
$title = $items['value'];
}
echo $results;
}
我也尝试过 DOMXPath 和 GetElementsByTagName 但无济于事。
基本上,我被困住了。我已经尝试了每种方法的多种变体,并遇到了很多错误,我感觉自己在原地打转。有更多 Xpath 或 XSLT 经验的人有一个想法吗?
最佳答案
考虑以下纯 XSLT 解决方案(不需要 foreach
循环),它可以处理节点重新排序,甚至最终输出,因为 XSLT 可以将 XML 内容转换为文本(即 PHP 字符串),当然甚至 HTML。
保持整个 CURL 调用不变,但替换嵌套的 foreach
循环。下面的 XSLT 脚本作为字符串嵌入,需要在 .ini 文件中启用 PHP 的 php_xsl
扩展才能访问 PHP 的内置 XSLT 1.0 处理器(即 libxslt):
// ... same CURL call ...
// Parse those results and print only what is needed for Citation format
$cxml=simplexml_load_string($data);
$xslstr = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="text"/>
<xsl:strip-space elements="*"/>
<xsl:template match="DocSum">
<xsl:if test="Item[@Name=\'AuthorList\' and .!=\'\']">
<xsl:for-each select="Item[@Name=\'AuthorList\' and .!=\'\']/*">
<xsl:value-of select="." />
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each><xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'FullJournalName\' and .!=\'\']">
<xsl:value-of select="concat(\'<strong>\', Item[@Name=\'FullJournalName\'],
\'</strong>\')" />
<xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'Title\' and .!=\'\']">
<xsl:value-of select="Item[@Name=\'Title\']" /><xsl:text>, </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'Volume\' and .!=\'\']">
<xsl:value-of select="Item[@Name=\'Volume\']" /><xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'Issue\' and .!=\'\']">
<xsl:value-of select="Item[@Name=\'Issue\']" /><xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'PubDate\' and .!=\'\']">
<xsl:value-of select="Item[@Name=\'PubDate\']" /><xsl:text>. </xsl:text>
</xsl:if>
<xsl:if test="Item[@Name=\'PubTypeList\' and .!=\'\']">
<xsl:for-each select="Item[@Name=\'PubTypeList\']/*">
<xsl:value-of select="." />
<xsl:if test="position() != last()">
<xsl:text>, </xsl:text>
</xsl:if>
</xsl:for-each><xsl:text>. </xsl:text>
</xsl:if>
<xsl:text><br><br></xsl:text>
</xsl:template>
</xsl:stylesheet>';
$xsl=simplexml_load_string($xslstr);
// XSLT TRANSFORMATION
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);
$newXML = $proc->transformToXML($cxml);
echo $newXML;
输出
关于php - 解析 PubMed 查询的curl结果并将其格式化为引文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41168505/
我以前从未做过任何 curl ,所以需要一些帮助。我试图从示例中解决这个问题,但无法理解它! 我有一个 curl 命令,我可以从 Windows 命令行成功运行该命令,该命令行在 Solr 中索引 p
curl -v有什么区别和 curl -I ? 我可以看到 -v是冗长的和 -I是标题。有什么具体的吗? 最佳答案 -I (大写字母 i)在 curl 中表示“没有正文”,对于 HTTP 表示发送 H
我正在使用curl php API访问FTP链接。在特定站点上,它给出错误代码9(拒绝访问)。但是,可以从IE和Firefox访问该链接。 然后,我运行curl命令行,它给出了相同的“访问拒绝”结果。
我已经使用curl有一段时间了,它可以正常工作,但是使用使用用户'domain\username'来验证curl的代理时,无法请求授权。授权方法是NTLM。此代码放入批处理文件中。 代码: curl
“curl”默认使用哪些证书? 例子: curl -I -L https://cruises.webjet.com.au 在 Ubuntu 15.04 上失败 curl: (60) SSL certi
我知道终端输出的一部分是请求的持续时间,剩余时间等。但是是否有一些文档指定了curl命令的终端输出的每一列到底是什么?手册页上的内容非常稀疏。 最佳答案 可能不容易找到,但已在the curl boo
我想通过 curl 在我自己的云服务器上的特定文件夹中上传文件。例如:http://www.myowncloudserver.com/remote.php/webdav/{MY_FOLDER}。此时我
我的网站上有一个密码保护的Web文件夹,我正在使用Curl在另一个域上获取该文件夹,我想要的是:当我尝试打开URL时,应该问我用户名和密码,而不是让它显示“需要授权”。 例: http://www.e
有没有一种方法可以通过简单的Curl获取Rabbitmq中队列的大小(剩余消息)? 类似于curl -xget http://host:1234/api/queue/test/stats 谢谢 最佳答
关闭。这个问题是opinion-based .它目前不接受答案。 2年前关闭。 锁定。这个问题及其答案是locked因为这个问题是题外话,但具有历史意义。它目前不接受新的答案或互动。 我最近开始在我的
我想访问需要用户名/密码的 URL。我想尝试用curl 访问它。现在我正在做类似的事情: curl http://api.somesite.com/test/blah?something=123 我收
我正在尝试使用 CURL 进行查询ElasticSearch 中的命令在windows平台。 例如:localhost:9200/playground/equipment/1?pretty 我收到一条
我正在尝试使用 Docker 构建和运行 Marklogic 实例。 Marklogic 提供了一些不错的 http api,所以,作为最终 CMD在 Dockerfile 中,我运行两个脚本,它们通
我正在尝试通过 cURL 检索网页的内容(比方说 http://www.foo.com/bar.php )。 当我在浏览器中加载网站时,加载页面时会出现动画,页面最终会显示出来。 但是使用 cURL,
我正在尝试使用带代理的命令行 CURL 获取响应状态代码。 这会返回整个页面,但我只想要状态代码。我怎么做?谢谢。 curl -sL -w -x IP:PORT "%{http_code}\n""ht
我有一段代码检查 http/s 端点的状态和加载时间。然后我会为每个顶级页面检查 1 级 href,以检查页面引用的所有内容是否也加载了 200。 (我查了50个顶级页面,每个顶级页面平均有8个链接)
curl --upload-file 和 curl --form file=@/path/file 有什么区别?这些 HTTP 请求有何不同? 最佳答案 --上传文件 (使用 HTTP 或 HTTPS
我正在尝试使用 system-curl 安装 cmake,使用 ./bootstrap --system-curl,如 here 所示.这样做,我得到了: -- Could NOT find
我需要使用 Curl 下载 Youtube 视频的特定部分。 (假设我想下载前 2MB)我在 Curl 中使用 -r 开关来实现这一点。它适用于非 YouTube 链接,但 Youtube 链接会忽略
我希望在使用 curl 命令从远程服务器下载文件后,将时间戳或日期添加到文件名中。我知道您可以使用 -o 来指定您要为文件命名的内容。我看到过这样的建议:-o "somefile $(date +\"
我是一名优秀的程序员,十分优秀!