i write this code in php in localhost is work but in host not work
word_list = ['loss', 'fault', 'slip', 'fall', 'injury']
data_list = [('there was a slip and fall', 150000), ('injury and loss', 100000), ('injury at fault', 50000)]
Output = [('injury', 75000), ('loss', 100000), ('slip', 150000), ('fall', 150000), ('fault', 50000)]
use in index:
function cURL($url, $ref, $header, $cookie, $p){
$ch = curl_init();//start curl
curl_setopt($ch, CURLOPT_URL, $url); //curl Targeted URL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $ref); //fake referer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
if ($p) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result = curl_exec($ch);
curl_close($ch);
if ($result){
return $result;
}else{
return '';
}
}
答案 0 :(得分:0)
您的主机可能会阻止机器人(?)简化一点 - 但这对我有用:
<?php
/**
* Created by CompuSolver.com.
* User: Hank Castello
* Date: 6/20/16
* Time: 10:27 AM
*/
function curlGet($url, $header){
$ch = curl_init();//start curl
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url); //curl Targeted URL
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.8 [en] (Windows NT 5.1; U)');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result = curl_exec($ch);
$httpResponse = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $result;
}
$targetURL = 'https://www.google.com/search?num=100&newwindow=1&site=&source=hp&q=web+developers&oq=web+developers&gs_l=hp.3..0l10.1547.5649.0.6045.15.11.0.4.4.0.115.760.8j1.9.0....0...1c.1.64.hp..2.12.714.0..0i131j0i3.xUKoFB0hpKM';
$header = array('Accept-Language: en-us,en;q=0.7,bn-bn;q=0.3','Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5');
$responsePg = curlGet($targetURL, $header);
echo $responsePg;