Здравствуйте, kov_serg, Вы писали:
_>Здравствуйте, Harvat, Вы писали:
H>>Подскажите, как можно на PHP загрузить код страницы формируемой по ссылке например такой:
H>>file_get_contents не отрабатывает...
_>Попробуйте curl-ом
Попробовал...но что то не так именно с этой страницей....
<?php
$url = 'https://earthquake.usgs.gov/earthquakes/map/';
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(
CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get
CURLOPT_POST =>false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file
CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 320, // timeout on connect
CURLOPT_TIMEOUT => 320, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init($url);
if (curl_errno($ch))
{
$error_msg = curl_error($ch);
echo $error_msg;
}
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
if ( $header['errno'] != 0 )
{
echo 'FUCK 1';
echo $errmsg ;
}
if ( $header['http_code'] != 200 )
{
echo 'FUCK 2';
echo $errmsg ;
echo $header['http_code'];
}
echo $header['content'];
?>
Здравствуйте, Harvat, Вы писали:
H>Попробовал...но что то не так именно с этой страницей....
Странно у меня работает. Попробуйте
https://mail.ru например.
Может у вас проблемы с https, дату проверте, посмотрите что пишет с CURLOPT_VERBOSE=>true
| Скрытый текст |
| * Hostname was NOT found in DNS cache
* Trying 13.224.241.97...
* Connected to earthquake.usgs.gov (13.224.241.97) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: C=US; ST=Virginia; L=Reston; O=U.S. Geological Survey; OU=USGS; CN=*.usgs.gov
* start date: 2018-08-06 00:00:00 GMT
* expire date: 2019-10-01 12:00:00 GMT
* subjectAltName: earthquake.usgs.gov matched
* issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert SHA2 High Assurance Server CA
* SSL certificate verify ok.
> GET /earthquakes/map/ HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0
Host: earthquake.usgs.gov
Accept: */*
Accept-Encoding: deflate, gzip
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=UTF-8
< Transfer-Encoding: chunked
< Connection: keep-alive
* Server nginx is not blacklisted
< Server: nginx
< Date: Wed, 24 Jul 2019 15:58:28 GMT
< Cache-Control: max-age=86400
< Expires: Wed, 24 Jul 2019 23:29:16 GMT
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Headers: accept,origin,authorization,content-type
< Strict-Transport-Security: max-age=31536000
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< X-Cache-Status: HIT
< Content-Encoding: gzip
< Vary: Accept-Encoding
< Age: 1238
< X-Cache: Hit from cloudfront
< Via: 1.1 bed6fe20b9fca9f4014b1a1d2375d67f.cloudfront.net (CloudFront)
< X-Amz-Cf-Pop: LHR62-C3
< X-Amz-Cf-Id: ODBhBP-itLzr1hui4kGCdeis9_tfIYv5efGKayV4tSlRZpuyj9nzPQ==
<
* Connection #0 to host earthquake.usgs.gov left intact
<!DOCTYPE html>
<html>
<head>
<title>Latest Earthquakes</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<link rel="stylesheet" href="/theme/site/earthquake/index.css"/>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons|Merriweather:400,400italic,700|Source+Sans+Pro:400,300,700"/>
<link rel="stylesheet" href="/lib/leaflet-0.7.7/leaflet.css"/>
<link rel="stylesheet" href="css/index.css"/>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="format-detection" content="address=no"/>
<meta name="format-detection" content="telephone=no"/>
<script id="_fed_an_ua_tag" async="async" src="/lib/Universal-Federated-Analytics-Min.1.0.js?agency=DOI&subagency=USGS&pua=UA-7320779-1"></script>
</head>
<body>
<main role="main" id="latest-earthquakes">
<noscript>
<p>
Javascript must be enabled to view our earthquake maps.
To access USGS earthquake information without using javascript, use our
<a href="/earthquakes/feed/v1.0/summary/2.5_day.atom">
Magnitude 2.5+ Earthquakes, Past Day ATOM Feed
</a> or our other <a href="/earthquakes/feed/">earthquake feeds</a>.
</p>
</noscript>
</main>
<script>var SCENARIO_MODE = false;var SEARCH_PATH = "\/earthquakes\/search";</script>
<script src="/lib/leaflet-0.7.7/leaflet.js"></script>
<script src="js/index.js"></script>
</body>
</html>
|
| |