curl scrape页面,没有显示搜索条目(没有js / cookie问题)

时间:2014-06-03 11:10:50

标签: php cookies curl scrape

我试图用curl和php抓一个网站。 现在我必须登录,这不是问题。

我使用Cookie登录,然后导航到包含产品的列表。 这些产品只是在他们的网站上用PHP打印。所以不是用javascript。

但是当我使用curl时,它表示无法找到品牌/搜索(没有返回结果)。 我更改了推荐人和主持人。

他们怎么能发现这一点,并且有可能绕过'它? 我有一个csv文件与他们的产品(从他们得到它),但没有与ammount和价格和描述。 所以我想填补自己的这一部分。

这是我的剧本:

include('brands.php');

$request = array(
    'username'=>'******',
    'pass'=>'*********',
    'submit'=>'',
    'part-submit'=>'',
    'referlink'=>'',
    'remember'=>1
);
$agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.website.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request));
$response = curl_exec($ch);
curl_close ($ch);

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_URL, $array[$_GET['k']]."&rpp=100");
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: website.com'));
curl_setopt ($ch, CURLOPT_REFERER, "http://www.website.com/linecard.php");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
var_dump(curl_getinfo($ch, CURLINFO_HEADER_OUT ));
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);

if ($curl_errno > 0) {
    die("cURL Error ($curl_errno): $curl_error\n");
}

echo $response;

提前致谢!

PS。删除了社交网站,将在需要时提供。为了他们的安全和谷歌点击

2 个答案:

答案 0 :(得分:0)

我不确定......也许我说的是一件蠢事......

无论如何,使用/和http_build_query的url结尾将创建var = value& var2 = value ...

因此请求将是:“http://www.website.com/var=value&var2=value

所以不正确......

网址应为http://www.website.com/search_page.php

度过愉快的一天

安东尼奥

答案 1 :(得分:0)

答案其实很简单.. 每次卷曲请求都会关闭我与网站的连接。 我不希望这样,所以这个问题的解决方案是在我登录网站后删除curl_close ($ch);

比一切正常!