将数据发布到返回的CURL内容

时间:2016-03-08 21:02:11

标签: javascript php html curl automation

我正在使用PHP来CURL登录网站。我正在尝试自动更改密码。

我可以登录该网站,然后转发到更改密码页面。

如何将数据发布到"更改密码"在CURL中返回的页面?

这是我用来调用登录页面的内容。

$ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_NOBODY, false);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);

    //set the cookie the site has for certain features, this is optional
    curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:44.0) Gecko/20100101 Firefox/44.0");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
    curl_exec($ch);

    //page with the content I want to grab
    curl_setopt($ch, CURLOPT_URL, "myurl.com");

    //do stuff with the info with DomDocument() etc
    $html = curl_exec($ch);
    echo $html;
    curl_close($ch);

它的HTML返回: enter image description here

应该注意的是,URL永远不会更改,登录页面只需自我提交并使用新框刷新。

我可以使用Javascript填写表单并在$ html变量中提交吗?

0 个答案:

没有答案