【问题标题】:Craigslist, CURL, Simple PHP DOM IssuesCraigslist、CURL、简单的 PHP DOM 问题
【发布时间】:2010-08-09 05:38:55
【问题描述】:

我正在使用 CURL 登录 Craigslist 以获取我已发布列表的状态。我遇到的问题是将 HTML 从 CURL $output 传输到 file_get_html。虽然 Craigslist 状态实际上嵌套在 TR 元素中,但我只是想测试最基本的功能,看看事情是否通过(即链接抓取)。他们不是。

例如,这不起作用:

$cookie_file_path = getcwd()."/cookie.txt";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://accounts.craigslist.org/login?LoginType=L&step=confirmation&originalURI=%2Flogin&rt=&rp=&inputEmailHandle='.$email.'&inputPassword='.$password.'&submit=Log%20In');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.craigslist.org');

$agent = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)";
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);

$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo $output;

//

include_once('simple_html_dom.php');
$html = file_get_html($output);
//find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>'; 

我知道该表达式有效,因为如果我输入“http://google.com”或其他内容,它会返回链接。

【问题讨论】:

  • 你确定 cURL 已经正确登录了吗?
  • 绝对积极。回显输出会显示我的帐户页面。

标签: html dom curl craigslist


【解决方案1】:

应该是这样的

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, 'http://www.sitename.com');  
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);  
$str = curl_exec($curl);  
curl_close($curl);  

$html= str_get_html($str); 

【讨论】:

    【解决方案2】:

    您不应该使用 str_get_html 而不是 file_get_html 吗? 因为 $ouput 是一个字符串!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-25
      • 1970-01-01
      • 2011-10-30
      相关资源
      最近更新 更多