使用curl、密码和用户名获取外部网页
我使用curl和php代码以字符串形式检索网页
:
$ch = curl_init();
// the external url
$url = 'http://cursos.puc.cl/eaa220a-1/correo/main.html';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// get the source code
$html = curl_exec($ch);
但是该网页要求输入用户名和密码。我不知道如何管理这个。 谢谢!
im retreiving a webpage as a string using curl and php
code:
$ch = curl_init();
// the external url
$url = 'http://cursos.puc.cl/eaa220a-1/correo/main.html';
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt ($ch, CURLOPT_HTTPHEADER, array (
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: en-us,en;q=0.5", "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7"
));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
// get the source code
$html = curl_exec($ch);
however the webpage, asks username and passowrd to enter. I have no idea on how to manage this.
Thx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从此处:
您可以阅读有关
curl_setopt() 的更多信息
此处。From here:
You can read more about
curl_setopt()
here.