我从json源读取数据时出错,我收到空白页错误。
我犯了一个错误。
我只想获得BetTypeId = 3的类别。
你可以帮忙吗?{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmit": true,
"noEmitHelpers": false,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
],
"plugins": [
{
"name": "tslint-language-service"
}
]
},
"exclude": [
"node_modules",
"dist"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
Everyone please help me, many thanks!
答案 0 :(得分:0)
您要获取数据的目标网站将检查浏览器代理。
添加代理并修复Scuzzy指出的问题,然后您的代码就可以运行。
您可以参考以下代码。请注意,您的xml格式可能有错误,这将导致浏览器无法正常显示响应数据。但我确实收到了回复<Maclar><ulke="Şampiyonlar Ligi" tarih="2018-02-13T22:45:00" /></Maclar>
代码:
<?php
error_reporting(1);
header("Content-type: text/xml; charset=utf-8");
$agent= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://www.misli.com/scripts/BetList.aspx?action=get&BetTypeId&3",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_USERAGENT=>$agent,
CURLOPT_HTTPHEADER => "accept: application/json"
));
$ok = curl_exec($curl);
//echo $ok;
$ok = json_decode($ok);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}
else {
echo "<Maclar>";
if($ok[0]->BetTypeId=="3")
{
$tarih = $ok[0]->CloseDate;
$ulke = $ok[0]->CountryName;
echo '<ulke="'.$ulke.'" tarih="'.$tarih.'" />';
}
echo "</Maclar>";
}
?>
希望它有所帮助。