페이지의 html 콘텐츠 (출처)를 검색해야합니다 (예 : www.google.com 페이지). 그렇다면 나는 PHP를 사용하여 file_get_contents
또는 curl_init
을 사용할 수 있습니다.암호가 있으면 PHP가 암호 필요 페이지의 내용을 검색합니까?
정확히 이곳에 누군가의 질문과 같이 나를 위해 그 다음
How do I get the HTML code of a web page in PHP?
하지만 더, 일부 페이지는 은 액세스 필수 있습니다.
하지만 액세스 권한을 부여하고 암호를 알고 있습니다.
은 (는 형태와 비밀번호를 물어 말할 수 있습니다 암호는 "ABCD"입니다.)
그래서 나는 그것을 읽고 어떻게 프로그래밍 PHP와 페이지? 는 (나를 위해, 대답을) 업데이트 :나는
curl-setopt
suggested by Bekzat Abdiraimov below과 해결책을 발견했다. 그럼 내가 여기 어딘가에서 발견하고 수정 된 코드를 여기에 게시 :
<?php
function curl_grab_page($url, $ref_url, $data, $login, $proxy, $proxystatus){
if($login == 'true') {
$fp = fopen("cookie.txt", "w");
fclose($fp);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if ($proxystatus == 'true') {
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
}
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $ref_url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
curl_setopt($ch,CURLOPT_URL,$ref_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1);
ob_start();
$data = curl_exec($ch);
ob_end_clean();
curl_close($ch);
return $data;
}
/*
* $auth_processing_url .. is the posted 'action' url in login form like <form method=post action='http://www.abc.com/login.asp'> So it should be like: "http://www.abc.com/login.asp"
* $url_to_go_after_login .. is the url you want to go (to be redireced) after login
* $login_post_values .. are the form input names what Login Form is asking. E.g on form: <input name="username" /><input name="password" />. So it should be: "username=4lvin&password=mypasswd"
*/
echo curl_grab_page($auth_processing_url, $url_to_go_after_login, $login_post_values, "true", "null", "false");
?>
http://stackoverflow.com/questions/1304974/set-authorization-header- using-php-and-curl –
네,'curl-setopt'가 올바른 해결책이라는 것을 알았습니다. 코드를 게시하지 않은 경우에도이 질문을 대답으로 설정했습니다. 그러나 그것의 충분히 ok, 나는 그것을 게시하고있다. 감사!! ;) –