php - POST 值并获取页面源

标签 php javascript html

<分区>

我正在尝试使用 html 表单向页面发布一个值并获取该页面的源。

我可以使用 $html = file_get_html('http://www.exam.com/results/');

但在获取源之前,我需要先将值 POST 到该页面,然后再获取源。

假设我应该发布值的其他页面是 http://www.exam.com/results/

我创建了一个用于提交值的表单。

<form method="post" action="http://www.exam.com/results/">

<input type="hidden" value="900358967" name="eid">
<input name="confirm" type="submit" value="Enter" >

</form>

所以它会 POST 值并在该页面上显示数据,但是如何获取带有数据的页面源?

这可能吗?我到处搜索并试图捕获它,但我不知道如何在 POST-ing 值后捕获它。

最佳答案

我认为您必须尝试使用​​ CURL

//set POST variables
$url = 'http://www.exam.com/results/';
$fields = array(
'eid' => urlencode('900358967')
);
$fields_string = "";

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

关于php - POST 值并获取页面源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15922617/

相关文章:

php - 布伦特里 iOS : fatal error 'Braintree_Configuration' not found

javascript - 在 Vue 组件中使用 CSS 变量(作用域)

javascript - 如何在 jQuery 中根据表行按钮位置打开 UL?

php - mysql View 减少

php - laravel 5.4 中两种不同的身份验证模型

php - jQuery 日期选择器不工作 - Laravel 应用程序

javascript - 测试创建 DOM 组件列表的函数

javascript - 这个字符串替换函数的目的是什么?

html - 如何在父 div 中居中放置多个 div 元素?

javascript - highcharts 列宽度和边框顶部