获取卷曲的交互式网页

时间:2015-05-17 17:47:09

标签: php apache curl

一般信息:

我目前正致力于domain.com,这是公开的。 m1.domain.com上的domain.com是可从m1.domain.com访问的私人服务器。

我需要做什么:

我需要从domain.com获取一个网页,并将其添加到m1中的php网页。如果iframe不是私有的,那么domain.com\m1就是完美的,但确实如此。

我做了什么:

到目前为止,我已经设法获取页面并使其可访问。当我访问domain.com\m1时,我被重定向到登录页面,但是一旦我输入我的凭据并按Enter键,curl就无法管理下一个重定向,而是将浏览器中的URL从domain.com\session更改为m1.domain.com。请务必注意,当我从m1.domain.com\session登录时,下一页为 curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

问题:

1)为什么重定向失败,即使我已经使用过:

<?php

    define("COOKIE_FILE", "cookie.txt");

    # Login the user
    $ch = curl_init('');
    curl_setopt ($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);
    curl_setopt ($ch, CURLOPT_COOKIEFILE, COOKIE_FILE);
    curl_setopt($ch, CURLOPT_HEADER, true);

    curl_setopt($ch, CURLOPT_URL, "m1.domain.com");
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    $output = curl_exec($ch);
    echo $output;
    curl_close($ch);
?>

2)如果您对如何使其正常工作有任何其他意见,请告诉我。

以下是整个代码:

var list1 = ...
var list2 = ...

var addNode = function(nodeId, array) {
  array.push({id: nodeId, children: []});
};

var placeNodeInTree = function(nodeId, parent, treeList) {
  return treeList.some(function(currentNode){

    // If currentNode has the same id as the node we want to insert, good! Required for root nodes.
    if(currentNode.id === nodeId) {
      return true;  
    }

    // Is currentNode the parent of the node we want to insert?
    if(currentNode.id === parent) {

      // If the element does not exist as child of currentNode, create it
      if(!currentNode.children.some(function(currentChild) {
        return currentChild.id === nodeId;
      })) addNode(nodeId, currentNode.children);

      return true;
    } else {

      // Continue looking further down the tree
      return placeNodeInTree(nodeId, parent, currentNode.children);
    }
  });
};

var mergeInto = function(tree, mergeTarget, parentId) {
  parentId = parentId || undefined;
  tree.forEach(function(node) {

    // If parent has not been found, placeNodeInTree() returns false --> insert as root element
    if(!placeNodeInTree(node.id, parentId, mergeTarget)){
      list1.push({id: node.id, children:[]});
    }

    mergeInto(node.children, mergeTarget, node.id);

  });
};

mergeInto(list2, list1);

document.write('<pre>');
document.write(JSON.stringify(list1, null, 4));
document.write('</pre>');

0 个答案:

没有答案