如何从远程网址获取HTML?

Goood day.

I have this link

If i open link in blowser i see window test

I would like get html element with id TarifValue

for this i use code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://www.russianpost.ru/autotarif/Autotarif.aspx?viewPost=26&countryCode=643&typePost=1&viewPostName=undefined&countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F&typePostName=undefined&weight=1100&value1=2650&postOfficeId=123456');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);

$output = curl_exec($ch);

curl_close($ch);

but echo $output show next code:

<html>
<head></head>
<body onload="document.myform.submit();">
<form method="post" name="myform" style="visibility:hidden;"><input id="key" name="key" value="497947">
<input type="submit">
</form>
</body>
</html>

Tell me please how rigth get html when me need ?

You can try with this parser http://simplehtmldom.sourceforge.net/. One of the best I found so far.

$html = file_get_html("http://www.russianpost.ru/autotarif/Autotarif.aspx?viewPost=26&countryCode=643&typePost=1&viewPostName=undefined&countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F&typePostName=undefined&weight=1100&value1=2650&postOfficeId=123456");

echo $html->find("#TarifValue", 0).textContent;

The content of that page is being dynamically loaded with a code in a form. Therefore, to get the HTML, you have to submit the form with the proper code.

I ran the following code:

$dom = new DOMDocument();
@$dom->load("http://www.russianpost.ru/autotarif/Autotarif.aspx?viewPost=26&countryCode=643&typePost=1&viewPostName=undefined&countryCodeName=%D0%A0%D0%BE%D1%81%D1%81%D0%B8%D0%B9%D1%81%D0%BA%D0%B0%D1%8F%20%D0%A4%D0%B5%D0%B4%D0%B5%D1%80%D0%B0%D1%86%D0%B8%D1%8F&typePostName=undefined&weight=1100&value1=2650&postOfficeId=123456");
echo $this->to_html($dom->saveHTML());

The output was:

<html>
<head></head>
<body onload="document.myform.submit();"><form method="post" name="myform" style="visibility:hidden;">
<input id="key" name="key" value="675356"><input type="submit">
</form></body>
</html>

It looks like a security measure with the code being generated each time. In order to get the HTML you want, you could use cURL to pass the form data with the post method. But to do that, you need to send the proper code.