开发者

PHP cURL and SimpleHTMLDom - Can't get ASP Viewstate Value

As the title says, how can I get the ASP ViewState Value? I'm using the code below that I thought would work. Thanks!

// 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',
        'Search:txtCaseNumber' => '',
        'Search:txtCompanyName' => '',
        'Search:txtLastName' => '',
        '__EVENTTARGET' => urlencode('Search:dgSearch:_ctl14:_ctl2'),
        '__VIEWSTATE' => 'dDwtMjk2Mjk5NzczO3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDE+Oz47bDx0PDtsPGk8Mz47aTwxOT47PjtsPHQ8dDw7cDxsPGk8MD47aTwxPjt开发者_如何转开发pPDI+O2k8Mz47aTw0PjtpPDU+Oz47bDxwPDIwMDY7MjAwNj47cDwyMDA3OzIwMDc+O3A8MjAwODsyMDA4PjtwPDIwMDk7MjAwOT47cDwyMDEwOzIwMTA+O3A8MjAxMTsyMDExPjs+Pjs+Ozs+O3Q8QDA8Ozs7Ozs7Ozs7Oz47Oz47Pj47Pj47Pj47PmVlaXw5JK161vti9TC+QMdeTNQI'
    );

    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);

    // Create a DOM object
    $html = new simple_html_dom();

    // Load HTML from a string
    $html->load($output);

    // Find all images
    $value = $html->find('input[name="__VIEWSTATE"]');

    foreach ($value as $v) {
        echo $v->value;
    }

    //echo $value->value;

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

    //$output;


It would appear as though simple_html_dom is unable to parse some of the HTML. You can "clean" the HTML up through HTML Tidy. Add this before you load $output into simple_html_dom

$tidy = new tidy();
$output = $tidy->repairString($output);

Also you do not need "" around the attribute name.

HTML Tidy is an extension and will need to be loaded by PHP to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜