0

我是一个卷曲新手。我正在模拟我的浏览器与特定服务器的对话。浏览器对一个页面、一些 CSS 文件和一些图像文件发出几个 GET 请求。

我想将我的结果打印为可浏览的网页。如何将所有这些文件合并到一个页面中?另外,如何使页面上的链接显示为绝对 URL,而不是全部链接到我的网络服务器?

# Create the PHP/CURL session
$ch = curl_init();

# Define target page
$target = ADDR;
curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_URL, $target); // Define target site
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // Return page in string
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tell PHP/CURL where to write cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); // Tell PHP/CURL which cookies to send
$page = curl_exec($ch);

$tmp = return_between($page, "<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"","\" />", EXCL );
$token = urlencode($tmp);
$tmp = return_between($page, "<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"","\" />", EXCL );
$token1 = urlencode($tmp);

# Define the login form data
$target = ADDR;
$form_data="__VIEWSTATE=".$token1."&__EVENTVALIDATION=".$token."&SearchType=rbSearchTypeBirth&txtSurname=".$surname."&txtGivenNames=".$givenname."&txtFromYear=".$datefrom."&txtToYear=".$dateto."&txtSpouseSurname=&txtSpouseGivenNames=&txtFather=&txtMother=&dropdownlistGender=M&txtLocation=&DummyForEnterSubmit=&btnSubmit=Search&hidPageNumber=1&hidPageTotal=1";

curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
//curl_setopt($ch, CURLOPT_REFERER, ADDR);
curl_setopt($ch, CURLOPT_URL, $target);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header_array);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8');
curl_setopt($ch, CURLOPT_POSTFIELDS, $form_data);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt"); // Tell PHP/CURL where to write cookies
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt"); // Tell PHP/CURL which cookies to send
$page = curl_exec($ch);

echo $page;
4

0 回答 0