我想通过web程序登录一个网站,然后获取里面页面的数据,可以么?谢谢!

iStringTheory 2004-08-25 09:17:06
具体是这样的:

登 录
我的程序-------->第三方web网站(需要用户名、密码登录)------>获取目标网站内部页面的数据

这整个过程都是通过程序完成的,请问能否可行?谢谢!
...全文
540 42 打赏 收藏 转发到动态 举报
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangzixp 2004-09-04
  • 打赏
  • 举报
回复
要获取session name很容易。随便在网上down一个HTTP监控软件,监控一次你正常登陆该站的过程就可以了。
iStringTheory 2004-08-28
  • 打赏
  • 举报
回复
谢谢~~~
piner 2004-08-27
  • 打赏
  • 举报
回复
以前写的一个class,可以根据自己的需要做调试
piner 2004-08-27
  • 打赏
  • 举报
回复
<?php
class curl
{
var $ch = 0;
var $time = 3; //尝试判断URL正确性次数
var $urlRight = false; //URL是否正确
var $content; //官方返回信息
var $errMsg = ""; //返回的错误信息

// 构造函数
function curl()
{
$this->init();
}
// 初始化curl
function init()
{
$this->ch = curl_init();
}
// configure protocol
function get_Protocol($prot)
{
$protocolArr = explode(":", $prot);
$protocol = strtolower($protocolArr[0]);
return $protocol;
}

// 设置次数
function setTimes($times) {
$this->time = ($times > 0) ? $times : $this->time;
}

// 获取页面
function getPage($url, $header = 0) {
if (! $this->ch)
{
$this->errMsg = "初始化对象失败!";
return;
}
if ($this->checkURL($url) != 1)
{
$this->errMsg = "无效的URL路径!";
return;
}

curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_POST, 1);

if ($this->get_Protocol($url) == 'https')
{
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}

if($header) {
curl_setopt($this->ch, CURLOPT_VERBOSE, 1);
curl_setopt($this->ch, CURLOPT_HEADER, 1);
}
else {
curl_setopt($this->ch, CURLOPT_VERBOSE, 0);
curl_setopt($this->ch, CURLOPT_HEADER, 0);
}

curl_setopt($this->ch, CURLOPT_COOKIEJAR, "-");
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 180);

return curl_exec($this->ch);
}

// 登录
function login($url, $fields, $refererURL=null)
{
if (! $this->ch)
{
$this->errMsg = "初始化对象失败!";
return;
}
/*
if ($this->checkURL($url) != 1)
{
$this->errMsg = "无效的URL路径!";
return;
}
*/
if( $refererURL )
{
curl_setopt($this->ch, CURLOPT_REFERER, $refererURL);
}
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_POST, 1);

if ($this->get_Protocol($url) == 'https')
{
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}

curl_setopt($this->ch, CURLOPT_COOKIEJAR, "-");
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 180);

$this-> content = curl_exec($this->ch);
// return $content;
}
// 退出
function logout($url, $referer_url=null)
{
if (! $this->ch)
{
$this->errMsg = "初始化对象失败!";
return;
}

if( $referer_url )
{
curl_setopt($this->ch, CURLOPT_REFERER, $referer_url);
}
curl_setopt($this->ch, CURLOPT_URL, $url);
curl_setopt($this->ch, CURLOPT_POST, 1);

if ($this->get_Protocol($url) == 'https')
{
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
}

curl_setopt($this->ch, CURLOPT_COOKIEJAR, "-");
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 180);

$this-> content = curl_exec($this->ch);
// return $content;
}



function getContent()
{
return $this->content; // 官方返回的HTML
}


// close curl
function close()
{
if ($this->ch)
{
curl_close($this->ch);
}
}
}



$curl = new curl;

$url = "http://www.test.com/login.php"; //form 的action
$fields = "username=test&password=test"; //用户名和密码
$curl-> login($url, $fields);
$content = getContent();

echo $content;
?>
iStringTheory 2004-08-27
  • 打赏
  • 举报
回复
自己顶~
surfchen 2004-08-26
  • 打赏
  • 举报
回复
OCR不一定准确的说。。呵呵
fire214 2004-08-26
  • 打赏
  • 举报
回复
对于 如输入验证码的功能,也可以利用模拟键盘来解决,让计算机自己切换到,如清华紫光图像识别就可以把相应的数字、符号提取出来,一切你自己需要操作的,模拟键盘都可以做到,只要自己有一套规矩就好了!
fire214 2004-08-26
  • 打赏
  • 举报
回复
关于这个问题,我研究了很长时间,无非就是让自己获取对方网站的信息,我也考虑了很多种办法,但是由于显示出来的方式不同,有的数据是静态的,有的数据是动态的,有的是数据库里的,弄得乱七八糟,最后我选用了用delphi采取模拟键盘的方法,最愚蠢的 ctrl+a +c +v 的方式先把对方的数据资料都调进我自己的数据库里,发现这个办法虽然笨,但是却无敌,也许你可以参照,目的达到了就好,其余的事情让计算机来做!
surfchen 2004-08-26
  • 打赏
  • 举报
回复
同意 Debian(乌鱼子)。。。。
zairwolfi 2004-08-26
  • 打赏
  • 举报
回复
验证码作为一个图片,不能通过程序分析象素得到它的数字么?我估计应该可以。
BiedySun 2004-08-26
  • 打赏
  • 举报
回复
主要是验证码问题。其实的都好说。
楼主的这个意思。其实极像网易通行证这样的东西来着。
你用HIDDEN来完成。
虚拟一次登陆,至于他用SESSION和COOKIE都无所谓的。因为服务器接到你虚拟信息后,会以为你已经成功进入 。
难点在于 abigfrog(千年精灵)(★JAVA★) 提出的难证码~!!!!
yzs1013 2004-08-26
  • 打赏
  • 举报
回复
用了session或指定了判断访问器类型的文件就无法通过其他方式能正常下载,socket或者curl都不例外
unixdotnet 2004-08-26
  • 打赏
  • 举报
回复
费话啦必须通过界面验证的东西不可能直接pass
yzs1013 2004-08-26
  • 打赏
  • 举报
回复
to liyujie2000(开心的鱼)
可能你漏了http://
<%
$fn=fopen("http://www.sohu.com","r");
$nr=fread($fn,500);
fclose($fn);
preg_match("/<title>(.*)<\/title>/",$nr,$nn);
echo $nn[1];
%>
结果:搜狐首页(我这里访问正常)
Debian 2004-08-26
  • 打赏
  • 举报
回复
拜托,你们都有没有头脑。
如果对方在服务器端应用了如输入验证码的功能,用什么都没戏。
iStringTheory 2004-08-26
  • 打赏
  • 举报
回复
curl怎么应对session验证?
iStringTheory 2004-08-26
  • 打赏
  • 举报
回复
好的,谢谢~
iStringTheory 2004-08-26
  • 打赏
  • 举报
回复
yangzixp(扬子.net):

可否告知什么软件获取网站的session name?是否只需一次获取?还是别的什么?
unixdotnet 2004-08-26
  • 打赏
  • 举报
回复
通过socket或者curl都可以
unixdotnet 2004-08-26
  • 打赏
  • 举报
回复
如果用户浏览器打开了cookie,那么session的传递是通过cookie的,所以你可以臆造,格式参照http协议,内容就像用flashget下载文件时程序里面的提示内容,以前phpx.com也讨论,可以去搜索看看.
加载更多回复(22)

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧