echo "\t" . HTTP::ConvertRelativeToAbsoluteURL($result["url"], $row->href) . "\n"; } } } $result = $web->Process("https://www.barebonescms.com/"); if (!$result["success"]) { echo "[FAIL] An error occurred. " . $result["error"] . "\n"; } else { if ($result["response"]["code"] != 200) { echo "[FAIL] An unexpected response code was returned. " . $result["response"]["line"] . "\n"; } else { echo "[PASS] The expected response was returned.\n"; $html->load($result["body"]); $rows = $html->find('a[href]'); foreach ($rows as $row) { echo "\t" . HTTP::ConvertRelativeToAbsoluteURL($result["url"], $row->href) . "\n"; } } } // Test asynchronous access. $urls = array("http://www.barebonescms.com/", "http://www.cubiclesoft.com/"); // Build the queue. $helper = new MultiAsyncHelper(); $pages = array(); foreach ($urls as $url) { $pages[$url] = new WebBrowser(); $pages[$url]->ProcessAsync($helper, $url, NULL, $url); } // Mix in another file handle type for fun. $fp = fopen(__FILE__, "rb"); stream_set_blocking($fp, 0);
public function ExtractForms($baseurl, $data) { $result = array(); if ($this->html === false) { $this->html = new simple_html_dom(); } $this->html->load($data); $html5rows = $this->html->find("input[form],textarea[form],select[form],button[form],datalist[id]"); $rows = $this->html->find("form"); foreach ($rows as $row) { $info = array(); if (isset($row->id)) { $info["id"] = trim($row->id); } if (isset($row->name)) { $info["name"] = (string) $row->name; } $info["action"] = isset($row->action) ? HTTP::ConvertRelativeToAbsoluteURL($baseurl, (string) $row->action) : $baseurl; $info["method"] = isset($row->method) && strtolower(trim($row->method)) == "post" ? "post" : "get"; if ($info["method"] == "post") { $info["enctype"] = isset($row->enctype) ? strtolower($row->enctype) : "application/x-www-form-urlencoded"; } if (isset($row->{"accept-charset"})) { $info["accept-charset"] = (string) $row->{"accept-charset"}; } $fields = array(); $rows2 = $row->find("input,textarea,select,button"); foreach ($rows2 as $row2) { if (!isset($row2->form)) { $this->ExtractFieldFromDOM($fields, $row2); } } // Handle HTML5. if (isset($info["id"]) && $info["id"] != "") { foreach ($html5rows as $row2) { if (strpos(" " . $info["id"] . " ", " " . $row2->form . " ") !== false) { $this->ExtractFieldFromDOM($fields, $row2); } } } $form = new WebBrowserForm(); $form->info = $info; $form->fields = $fields; $result[] = $form; } return $result; }