我有2个站点,一个主站点,一个外部站点。在主站点上,我使用Lucene来搜索它。问题是,我正在尝试搜索外部网站。
外部网站的表单操作:
<form action="https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT" method="post" name="search_tribute" >
我尝试过使用curl,但它只会在没有实际搜索的情况下调出搜索表单(字段也是空的)。
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, tname='hello');
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
任何提示?
我无法访问表单操作,因为它位于外部站点上。我提供的只是一个表单,在我提交时会链接到它。
答案 0 :(得分:1)
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("teamName" => "hello", "searchType" => "team"));
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
你能试试吗? 我很确定它应该是teamName而不是tName
答案 1 :(得分:0)
尝试将其放入数组中。 因为这将是$ _POST在另一方检查的变量
并检查了您的链接,该字段的teamName为
$fields = array("teamName"=>"julia");
然后..
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
所以你的完整代码是......
<?php
$ch = curl_init("https://secure.bcchf.ca/SuperheroPages/searchResults.cfm?Event=WOT");
$fields = array("teamName"=>"julia");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$output = curl_exec($ch);
var_dump($output);
curl_close($ch);
?>
答案 2 :(得分:0)
大多数搜索引擎使用GET
而非POST
..您可以尝试
// asumption
$_POST['search'] = "hello";
// Return goole Search Result
echo curlGoogle($_POST['search']);
function curlGoogle($keyword) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/search?hl=en&q=' . urlencode($keyword) . '&btnG=Google+Search&meta=');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FILETIME, true);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
或者如果你想发布那么
curl_setopt($ch, CURLOPT_POSTFIELDS, array("search"=>"hello"));
答案 3 :(得分:0)
你的php代码是无效的语法,它不能编译。
因此,如果这确实是您所拥有的,那么您的问题就是您的文件会产生致命错误。
话虽如此,这个问题很难回答,因为我们不知道您想从中获取搜索结果的网站。
尝试像这样修改你的行:
curl_setopt($ch, CURLOPT_POSTFIELDS, "search=hello");
或者
curl_setopt($ch, CURLOPT_POSTFIELDS, array("search" => "hello");
Maby它可以工作,但可能需要更多的帖子数据或元素名称不正确。
您必须查看表单或尝试提出请求并使用chromes开发人员工具或firebug进行查看。
外部网站还有很多方法可以阻止你正在做的事情,尽管可以以某种方式解决问题。
假设情况并非如此,我希望我可以帮助你。