php - 在 Curl 中通过 id 或 Name 获取元素

标签 php curl element

我的目标站点包含这样的代码

<form>
<input type="text" name="suggest" value="www.google.com">
<input type="submit" value="submit">
</form>

我用 Curl Php 获取这个页面

<?php
$url="http://mysite.com"; 
$ch = curl_init(); 
curl_setopt ($ch, CURLOPT_URL, $url); 
$result = curl_exec ($ch); 
echo $result;  
curl_close($ch);
?>

如何使用 id 或 name 获取元素值?例如,输入 name="suggest"中的“www.google.com”。谢谢你帮助我。

我不能像这样将此代码用于远程:

<?php
require 'Path/QueryPath.php';
qp('http://hipfile.com/bbgfom5ej9tm/zakhme_shaneie_haava_dvdrip.wmv.html/')-

find('[password="login"]')->writeHTML(); ?>

并返回这个错误

Fatal error: Uncaught exception 'QueryPathParseException' with message 'DOMDocument::load() [domdocument.load]: AttValue: " or ' expected in http://hipfile.com/bbgfom5ej9tm/zakhme_shaneie_haava_dvdrip.wmv.html/, line: 18 (C:\xampplite\htdocs\test1\Path\QueryPath.php: 2106)' in C:\xampplite\htdocs\test1\Path\QueryPath.php:2346 Stack trace: #0 [internal function]: QueryPathParseException::initializeFromError(2, 'DOMDocument::lo...', 'C:\xampplite\ht...', 2106, Array) #1 C:\xampplite\htdocs\test1\Path\QueryPath.php(2106): DOMDocument->load('http://hipfile....', 0) #2 C:\xampplite\htdocs\test1\Path\QueryPath.php(179): QueryPath->parseXMLFile('http://hipfile....', NULL, NULL) #3 C:\xampplite\htdocs\test1\Path\QueryPath.php(23): QueryPath->__construct('http://hipfile....', NULL, Array) #4 C:\xampplite\htdocs\test1\index.php(3): qp('http://hipfile....') #5 {main} thrown in C:\xampplite\htdocs\test1\Path\QueryPath.php on line 2346

可以帮我吗?我使用了两个 DOM 和 simplehtmldom 但不适合我。它仅适用于本地页面。

最佳答案

您必须使用 DOM 解析器。最近我一直在使用查询路径:http://querypath.org/

qp($result)->find('[name="name"]');

关于php - 在 Curl 中通过 id 或 Name 获取元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10548664/

相关文章:

jQuery 跳过前 3 个元素和最后一个元素

php - 将多个单维数组组合并转置为单个多维数组

php - 如果菜单位于不同的文件夹中,如何创建网站的 BASE URL?

post - cURL、SSL 和 POST

curl - 如何用 curl 欺骗搜索引擎机器人?

javascript - 在javascript中添加数组中的元素

PHP MySQL从下拉框选择中插入多个值

php mysql 操作顺序,似乎删除是一次性发生的

PHP Curl 图片上传

javascript - requestAnimationFrame 填充 : what's the element parameter for?