Php 获取gestis数据库的xml

Php 获取gestis数据库的xml,php,xml,curl,Php,Xml,Curl,我尝试获取此网站的内容(而不是xml): 通过curl或file获取php中的内容 您可以在任何浏览器中打开该网站,但每当我尝试使用php打开该网站以使内容自动化时,都会返回500错误 以下是使用的代码: <?php /* gets the data from a URL */ function get_data($url) { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url)

我尝试获取此网站的内容(而不是xml): 通过curl或file获取php中的内容

您可以在任何浏览器中打开该网站,但每当我尝试使用php打开该网站以使内容自动化时,都会返回500错误

以下是使用的代码:

<?php

/* gets the data from a URL */
function get_data($url) {
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$returned_content = get_data('http://gestis.itrust.de/nxt/gateway.dll/gestis_de/010520.xml?f=templates$fn=default-doc.htm$3.0');

echo $returned_content;

?>


有人知道如何通过php从该网站获取xml吗?

要打开的网站需要cookie形式的
vid=gestisdeu:sdbdeu
值才能工作:

Cookie: nxt/gateway.dll/vid=gestisdeu%3Asdbdeu;
请参阅curl文档,了解如何设置cookie或查看此webiste上已有的现有资料,例如,等等

注意,根据网站及其配置的变化,这可能会有所不同。所以从技术上讲,你的问题无法得到真正的回答,因为该网站没有任何关于HTTP请求要求的文档。因此,如果你提出这样的问题,你需要自己找出答案并提供答案

PHP示例:

$url = 'http://gestis.itrust.de/nxt/gateway.dll/gestis_de/010520.xml?f=templates$fn=default-doc.htm$3.0';
$options['http'] = ['header' => 'Cookie: nxt/gateway.dll/vid=gestisdeu%3Asdbdeu;'];
stream_context_set_default($options);
$content = file_get_contents($url);
var_dump($content);
输出:

string(104975) "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>DGUV-IFA GESTIS</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
</head>
<body>
    <html>
<head>
<META http-equiv="Content-Type" content="text/html">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="/nxt/gateway.dll/gestis_de/010520.xml?f=stylesheets$fn=gestis-doc.css$up=1$3.0" type="text/css">
<"...
字符串(104975)”
DGUV-IFA-GESTIS

为什么您有两个curl init调用,一个封装在函数中,另一个未封装在未使用的函数中。此外,您提供给我的链接
您正在查找的资源已被删除、名称已更改或暂时不可用。
,不是XML资源。啊,我放弃编写它。它仅在您需要时提供内容首先通过该链接打开它:但那也不是XML文件……但无论如何都不应该比curl获取任何内容?可能不会。还记得我是如何点击链接才能到达你想要的页面的吗?是的。你必须用curl模仿它。可能有保护措施阻止你删除他们的数据。