代码中的更正为cURL

时间:2015-12-26 14:30:31

标签: javascript php jquery html curl

我希望在我的网站上提供“在一个网站上提供服务”。 所以我决定使用cURL(在我尝试使用Iframe之前,但它不值得,因为该网站有广告,我想要特定部件等)所以基本上我想从该远程站点的特定标签(而不是div)在我的网站的网页上。我搜索了很多,因为我不知道php,发现cURL用于做我想要的。谷歌搜索后,我已经制作了这个简单的脚本

    <?php
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, "http://www.autogeneratelink.com/");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec ($curl);
    curl_close ($curl);
echo "$output";
?>

因为我不知道php我只能做这么多基本上这个代码所做的是在我的网页上显示整个网站但是我想要特定的部分(这个标签之间的东西<form method="POST" action=""></form>

此外,我尝试在我的网页中输入一个值,然后点击“生成”按钮,但它没有做任何事情。它只是刷新页面。

请帮我解决这个问题,我希望Button正常工作,以及仅在该标签之间的内容。

谢谢你帮助...

1 个答案:

答案 0 :(得分:0)

您可以对curl的结果运行preg_match以获取所需的HTML:

<?php
  $curl = curl_init();
  curl_setopt ($curl, CURLOPT_URL, "http://www.autogeneratelink.com/");
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  $html = curl_exec ($curl);
  curl_close ($curl);
  preg_match('/<form method="POST" action="">.*<\/form>/s', $html, $matches);
  $form = $matches[0];
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <link href="http://www.autogeneratelink.com/css/bootstrap.min.css" rel="stylesheet">
  <link href="http://www.autogeneratelink.com/css/autogl.css" rel="stylesheet">
  <style>
    button#submit{
      background-color: yellow;
    }
  </style>
</head>
<body>
  <h1>My Awesome Page</h1>
  <p>Hello!</p>
  <?php echo $form ?>
  <p>Bye!</p>
</body>
</html>

但是,表单由the following script提供支持,它向您控件之外的域上的PHP脚本发出Ajax请求。您将受到跨源政策的破坏,您的表格将无法运作。我不知道如何解决这个问题。遗憾!

此外,此时,您还应该开始考虑您正在做的事情的道德规范(即偷窃)。

相关问题