简体   繁体   English

使用PHP cURL搜索结果的网页 - 发布不起作用

[英]Scraping a Webpage for Results Using PHP cURL - Post Not Working

I'm new to using cURL, but from what I have read, the following should post the variables to the page, then print the result. 我是新手使用cURL,但根据我的阅读,以下内容应将变量发布到页面,然后打印结果。 The result prints, but it doesn't seem like the POST variables went because no results are generated. 打印结果,但似乎没有POST变量,因为没有生成结果。 FireBug doesn't show anything going either. FireBug也没有显示任何内容。 Any ideas what I'm doing wrong? 我有什么想法我做错了吗?

Thanks for your help! 谢谢你的帮助!

 // create curl resource
        $ch = curl_init();

        // set url
        curl_setopt($ch, CURLOPT_URL, "http://butlercountyclerk.org/bcc-11112005/ForeclosureSearch.aspx");


        $data = array(
            'Search:btnSearch' => 'Search',
            'Search:ddlMonth' => '1',
            'Search:ddlYear' => '2011'
        );


        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 

        //return the transfer as a string
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // $output contains the output string
        $output = curl_exec($ch);

        // close curl resource to free up system resources
        curl_close($ch);

        echo $output;

Based on the coding of the site, it appears that you're missing a number of variables. 根据网站的编码,您似乎错过了许多变量。 Take for example, the actual post request made to the search page: 例如,对搜索页面发出的实际发布请求:

__VIEWSTATE=dDwtMjk2Mjk5NzczO3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDE+Oz47bDx0PDtsPGk8Mz47aTwxOT47PjtsPHQ8dDw7cDxsPGk8MD47aTwxPjtpPDI+O2k8Mz47aTw0PjtpPDU+Oz47bDxwPDIwMDY7MjAwNj47cDwyMDA3OzIwMDc+O3A8MjAwODsyMDA4PjtwPDIwMDk7MjAwOT47cDwyMDEwOzIwMTA+O3A8MjAxMTsyMDExPjs+Pjs+Ozs+O3Q8QDA8Ozs7Ozs7Ozs7Oz47Oz47Pj47Pj47Pj47PmVlaXw5JK161vti9TC+QMdeTNQI&Search:ddlMonth=1&Search:ddlYear=2011&Search:txtCompanyName=&Search:txtLastName=&Search:txtCaseNumber=&Search:btnSearch=Search __VIEWSTATE = dDwtMjk2Mjk5NzczO3Q8O2w8aTwxPjs + O2w8dDw7bDxpPDE + Oz47bDx0PDtsPGk8Mz47aTwxOT47PjtsPHQ8dDw7cDxsPGk8MD47aTwxPjtpPDI + O2k8Mz47aTw0PjtpPDU + Oz47bDxwPDIwMDY7MjAwNj47cDwyMDA3OzIwMDc + O3A8MjAwODsyMDA4PjtwPDIwMDk7MjAwOT47cDwyMDEwOzIwMTA + O3A8MjAxMTsyMDExPjs + PJS +盎司+ O3Q8QDA8Ozs7Ozs7Ozs7Oz47Oz47Pj47Pj47Pj47PmVlaXw5JK161vti9TC + QMdeTNQI&搜索:ddlMonth = 1&搜索:ddlYear = 2011&搜索:txtCompanyName =&搜索:txtLastName =&搜索:txtCaseNumber =&搜索:btnSearch =搜索

This is post-feeding though URLDecode by the way. 顺便说一句,这是通过URLDecode进行后期馈送。 What this means though, is that your array of 3 values is missing data. 但是,这意味着您的3个数组的数组缺少数据。 At the very least, I'd suspect that Search:btnSearch=Search is missing, and would suggest that you implement all fields into your POST request. 至少,我怀疑Search:btnSearch = Search缺失,并建议您在POST请求中实现所有字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM