网站上抓取数据并且自动发帖到论坛程序

news/2024/5/10 15:37:16/文章来源:https://blog.csdn.net/ecitnet/article/details/1802496
近期本人闲来没事做了一个程序自动从一些BT网站上抓取数据并且自动发帖到我自己的论坛上,试用了几个月效果比较好,现在公布源代码供perl爱好者参考,欢迎广大perl爱好者一起沟通交流。
分几个程序组成
readcokie.pl 获取要上传主机的cookie一次获取永久在主机保存
fatie.pl         抓取源主机数据并自动发帖到目标主机
history.log   保存抓取过的数据
user.txt        发帖时使用的用户列表
..........

具体程序如下
readcokie.pl
======================
# -*- coding: gb2312 -*-
#$ua->post( $url, /%form )
#$ua->post( $url, /@form )
#$ua->post( $url, /%form, $field_name => $value, ... )
#This method will dispatch a POST request on the given $url, with %form or @form providing the key/value pairs for the fill-in form content. Additional headers and content options are the same as for the get() method.
#This method will use the POST() function from HTTP::Request::Common to build the request. See the HTTP::Request::Common manpage for a details on how to pass form content and other advanced features.
#$ua->get( $url )
#$ua->get( $url , $field_name => $value, ... )
#This method will dispatch a GET request on the given $url. Further arguments can be given to initialize the headers of the request. These are given as separate name/value pairs. The return value is a response object. See the HTTP::Response manpage for a description of the interface it provides.
#$ua->agent('Mozilla/5.0');
  use HTTP::Cookies;
  use HTTP::Request::Common qw(POST);
  use LWP::UserAgent;
    $ua = LWP::UserAgent->new;
  open(FILE,'D:/bin/posttools/自动发帖/bt区顶贴/cc8.cnsuk.net新沙加神话/data/user.txt');
  @file=<FILE>;
  for ($i=0;$i<=$#file;$i++){
    chomp($file[$i]);
    ($user,$pass)=split(/,/,$file[$i]);
    $ua->cookie_jar(HTTP::Cookies->new(file => "D://bin//posttools//自动发帖//bt区顶贴//cc8.cnsuk.net新沙加神话//data//$user//cookie.txt",
                                     autosave => 1));
    $req =POST 'http://www1.5hxy.com/bbs/login.asp',
              [UserName => $user,
              Userpass => $pass,
              IsSave => '1',
              Eremite => '1',
              ];
    $res=$ua->request($req);
    $ua->cookie_jar->save;
#     $ua = LWP::UserAgent->close;   
    }




fatie.pl
=============================

  use HTTP::Cookies;
  use LWP;
  $ua = LWP::UserAgent->new;
  $ua->agent("Mozilla/8.0";
#初始化参数
$n_file='D:/bin/posttools/自动发帖/bt区顶贴/cc8.cnsuk.net新沙加神话//';

###临时种子文件地址
#定义地址@url @postid @bankuainame  
$hhttp='http://cc8.cnsuk.net';
$url[0]='http://cc9.cnsuk.net/forum-2944-2.html';
$postid[0]='13';
$bankuainame[0]="$hhttp-游戏";

$url[1]='http://cc9.cnsuk.net/forum-2944-1.html';  
$postid[1]='13';
$bankuainame[1]="$hhttp-游戏";

$url[2]='http://cc9.cnsuk.net/forum-2905-2.html';  
$postid[2]='13';
$bankuainame[2]="$hhttp-游戏";

$url[3]='http://cc9.cnsuk.net/forum-2905-1.html';  
$postid[3]='13';
$bankuainame[3]="$hhttp-游戏";
while (1) {
  for ($u=0;$u<=$#url;$u++){
      $htms='';
      $res = $ua->get($url[$u]);
      $htms=$res->content;
      print "获取 $bankuainame[$u] 版块数据 /n";
      #获取后挑出有用的数据
      if ($res->is_success) {
          @html=();
          @html=split(//n/,$htms);
          @link=();
          @tid=();
          @tti=();
          for(@html){
#<a href="thread-50813-1-1.html" style="font-weight: bold;color: green">[04.19][BT游戏最新补丁发布专用贴][暂放]</a><span class="lighttxt">

                #if (m{^<a href="(viewthread/.php/?tid=)(/d+)&.*>(.*)</a>}){
                if (m{^<a href="(thread/-)(/d*)(/-/d*/-/d*/.html)".*?>(.*?)</a>}){
                    push(@link,$1.$2.$3);
                    push(@tid,$2);
                    push(@tti,$4);
                }
          }
      }
      print "挑出有用的数据 $#link 个 /n";
      #历史记录
      open (FILE,$n_file.'data/history.log');
      @history=();
      @history=<FILE>;
      close FILE;
      #用户记录
      open(FILE,$n_file.'data/user.txt');
      @usertxt=();
      @usertxt=<FILE>;
      close FILE;
      #提交记录
      print "读取用户信息 /n";
      #检查帖子是否在历史,不在就发帖
      $chazhao=0;#是否找到0没找到
      for ($x=0;$x<=$#tid;$x++){
        for ($a=0;$a<=$#history;$a++){
            if ($history[$a]==$tid[$x]){
                $a=$#history+1;
                $chazhao=1;   
            }
        }
        print "帖子$tti[$x] $tid[$x] 找到标志为 $chazhao/n";
        if ($chazhao==0){ #如果历史没有就发帖
            #获取源帖子内容
            $url="$hhttp/$link[$x]";
            $res = $ua->get($url);
            $htmls=$res->content;
            #open (FILE,'>D:/bin/posttools/自动发帖/bt区顶贴/bbs.btpig.com猪猪乐园/bin/temp.log'); #debug
            #print FILE $htmls;                                                                    #debug
            #close FILE;                                                                           #debug
            @html=();
            @html=split(//n/,$htmls);
            @torlink=();
            @tortid=();
            @torxylink=();
            @tortti=();
            $zd=0;
            #获取所有种子地址
                for(@html){
                #<a href="viewthread.php?tid=645515&extra=page%3D1" style="font-weight: bold;color: blue">[02.02][原创][美国][二战][二战电影五部][DVDRip][6.1G] 英文字幕</a>
                #<a href="attachment.php?aid=26721" target="_blank" class="bold">金庸群侠传全集★cc8cnsuk.net新沙加神话★VItas★.torrent</a> (2007-4-28 21:12, 17.35 K)<br>

                        if (m{<a href="(attachment/.php/?aid=)(/d+)".+?>(.+/.torrent)</a>}){
                        push(@torlink,$1.$2);
                        push(@tortid,$2);
                        push(@tortti,$3);
                        $zd=1;
                        }
                }
            #找到种子文件才发帖,否则不发帖
            if ($zd==1){
              $userc=int(rand($#usertxt));#选择哪个用户
              chomp($usertxt[$userc]);
              ($user,$pass)=split(/,/,$usertxt[$userc]);
              print "决定用户$userc发帖子/n";
              #获取种子
              @torxylink=();

              for ($f=0;$f<=$#tortid;$f++){
                $err=0;
                $url="$hhttp/$torlink[$f]";
                $res = $ua->get($url,referer=>$hhttp,);
                print "种子获取成功,开始上传种子/n";
                if ($res->is_success) {
                    $torrent=$res->content;
                    $filename="$n_file"."torrent//temp/.torrent";
                    open (FILE2,">$filename";
                    binmode(FILE2);
                    print FILE2 $torrent;
                    close FILE2;
                    #上传种子
                    w1:{$ua->cookie_jar(HTTP::Cookies->new(file => "$n_file"."data//$user//cookie/.txt",
                    autosave => 0));
                    $ua->timeout(240);
                    $response = $ua->post('http://www3.5hxy.com/bbs/UploadAttachment.asp',
                    Content_Type => 'form-data',
                    Content      => [ file => ["$filename"],
                                    ],
                    referer=>'http://www3.5hxy.com/bbs/',);
                    #获取上传目标种子地址
                    #<a target=_blank href=UpFile/UpAttachment/2007-2/20072731345.torrent>http://www.5hxy.com/UpFile/UpAtt ... 20072731345.torrent</a>
                    if ($response->content=~m{(<a target=_blank href=.*?/.torrent.*?>}m){
                      push(@torxylink,$1.$tortti[$f].'</a>');
                      }else{
                      if ($err<=5){#如果没有错误5次继续尝试上传
                        $err++;
                        goto w1;  
                        }                     
                      }
                    last w1;
                    }
                }
              print "种子上传完毕/n";
              #sleep 3;
              }
              #拆分源帖子
              $zzdaot=0;
              $zzdaow=0;
              for ($s=0;$s<=$#html;$s++){
                #找帖子头部
                if ($zzdaot==0){
                  if ($html[$s]=~m/<table width="95%" border="0" cellspacing="0" cellpadding="0"/){
                    $tou=$s+39; #+5是头部偏移量
                    $zzdaot=1;
                  }
                }elsif ($zzdaow==0){
                  if ($html[$s]=~m/<table width="95%" border="0" cellspacing="0" cellpadding="0"/){
                    $wei=$s-30; #尾部偏移量
                    $zzdaow=1;
                  }
                }
              }
              #如果只找到头没有找到尾那么尾偏移30;
              if ($zzdaot==1 and $zzdaow=0){
                $wei=$tou+30;
              }
              #获取所有图片地址
              print "获取所有图片地址/n";
              @imgh=();
              for($b=$tou;$b<=$wei;$b++){
                    @imgh=split(/ /,$html[$b]);
                    for($j=0;$j<=$#imgh;$j++){
                #<img src="http://img.album.pchome.net/02/71/78/71/efe60b699dcfb8277e0eb309ce4ee1ce.jpg" border="0" οnlοad="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnmοuseοver="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window/nCTRL+Mouse wheel to zoom in/out';}" οnclick="if(!this.resized) {return true;} else {window.open('http://img.album.pchome.net/02/71/78/71/efe60b699dcfb8277e0eb309ce4ee1ce.jpg');}" onmousewheel="return imgzoom(this);">
                      if ($imgh[$j]=~m{src="(.+/.jpg)"}){
                        $imgf=$1;
                          if ($imgf=~m/http/){
                            push(@img,"/[img/]$imgf/[/img/]";
                            }else{
                            push(@img,"/[img/]$hhttp/$imgf/[/img/]";
                            }
                          }
                      }
              }
              print "合并数据准备发帖/n";
              $constor='';
              #合并种子地址
              for ($b=0;$b<=$#torxylink;$b++){
                $constor.="<br><br> 本站种子地址torxylink[$b] <br><br>";
                }
              @torxylink=();
              #合并图片地址
              for ($b=0;$b<=$#img;$b++){
                $constor.="<br><br> $img[$b] <br><br>";
                }
              @img=();
              #合并要发送的数据
              $cons=$constor;
              for ($g=$tou;$g<=$wei;$g++){
                $cons.=$html[$g];
                }
              $cons=~s/<i.*?//>//mg;
              $cons=~s/<d.*?>//mg;
              $cons=~s/<//d.*?>//mg;
              $cons.="<br><br>此数据来自$hhttp/$link[$x] <br><br>";
              #####开始发帖子  哎,写了这么多终于可以发帖子了,真不容易
              $ua->cookie_jar(HTTP::Cookies->new(file => "$n_file"."data//$user//cookie/.txt",
                    autosave => 0));
                  $ua->timeout(240);
                  $url='http://www3.5hxy.com/bbs/AddTopic.asp?ForumID='.$postid[$u];
                  #开始发帖子
                  print "开始发帖/n";
                  $response = $ua->post( $url,
                          [ForumID => $postid[$u],
                          Subject => $tti[$x] ,
                          Body => $cons,
                          UpFileId=>1,
                          #content => $cons,
                          #DisableYBBCode => '0'
                          ],
                          referer=>'http://www3.5hxy.com/bbs/', );


            }
                      print "帖子 $tti[$x]$tid[$x] 记录历史完毕 /n";
                      open (FILE,">>$n_file".'data/history.log'); #回过帖子的记录起来
                      print FILE "$tid[$x]/n";
                      close FILE;
        }
      print "==================== $bankuainame[$u] =======================/n";
      $chazhao=0;
      }
  }
print "休眠1200秒 /n";
sleep 1200;
}
  
 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_842141.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

网站实时监控系统的设计与实现

引言  对网页监控比较成熟的技术是定时监控&#xff0c;即由用户设定时间间隔&#xff0c;系统按时对需监控的网页文件轮询一遍&#xff0c;来判断文件是否被非法删除或篡改。若发现&#xff0c;立即用备份盘上的备份文件进行恢复。这样的监控存在一个缺陷&#xff1a;被非法…

[BOF]高性能网站设计、开发、部署

北京 TechED 上&#xff0c;计划中的一个BOF&#xff08;同类人&#xff09;的主题是&#xff1a;高性能网站设计、开发、部署&#xff0c;下面是我初步整理需要讨论的主题&#xff1a; 网站是信息展示平台&#xff0c;它的核心职责是把信息展示出来。当然&#xff0c;他也有部…

值得网站开发者收藏的JAVASCRIPT图形图表库

http://www.uirss.com/blog-39451-6411.html 图表是数据图形化的表示&#xff0c;通过形象的图表来展示数据&#xff0c;比如条形图&#xff0c;折线图&#xff0c;饼图等等。可视化图表可以帮助开发者更容易理解复杂的数据&#xff0c;提高生产的效率和Web应用和项目的可靠性。…

seo按天扣费系统_扒拉一些搞SEO关键词排名赚钱的几个行业秘密

互联网上的赚钱方式各式各样&#xff0c;干什么的几乎都有&#xff0c;但是搞网站的、搞SEO的&#xff0c;最终目的也是赚钱&#xff0c;可是赚钱跟赚钱相比&#xff0c;SEO排名赚钱的还是出现了几个极端化。今天诺伊网小编给你深扒一些SEO行业的秘闻吧&#xff0c;估计很多干货…

:https web服务器ssl认证项目,网站启用https后的SSL的安全配置和检测

现在的网站通常开启SSL已经是标配了&#xff0c;不过&#xff0c;配置好了SSL后&#xff0c;还需要判断一下服务器部署的是否安全&#xff0c;如果没有配置好的话&#xff0c;会带来很多安全隐患。SSL/TLS 系列中有六种版本&#xff1a;SSL v2&#xff0c;SSL v3&#xff0c;TL…

国内的服务器网站,国内主流网站服务器

国内主流网站服务器 内容精选换一换在大型网络应用中&#xff0c;通常会使用多台服务器提供同一个服务。为了平衡每台服务器上的访问压力&#xff0c;通常会选择采用负载均衡来实现&#xff0c;提高服务器响应效率。云解析服务支持解析的负载均衡&#xff0c;也叫做带权重的记录…

国内外IGS数据及产品下载网站

国内外 IGS数据及产品下载网站 连接有所变更&#xff1a; CLK ,SP3 https://cddis.nasa.gov/archive/gnss/products/2220/ 本文是转载博客地址&#xff1a;https://blog.csdn.net/SmartTiger_CSL/article/details 一、转自http://geodesy.blog.sohu.com/274775667.html IG…

好吧我摊牌了,这是C++最好的5 个网站

相对其他语言来说&#xff0c;C 算是难度比较高的了&#xff0c;这一点无法否认。但是如果能有一些好的网站&#xff0c;则会让 C 的学习事半功倍。 那就来介绍几个最常用的&#xff08;最好的&#xff09;吧&#xff0c;包含了参考手册、教程、框架/库列表 ...... 1.cpprefer…

谷歌浏览器使用bing搜索引擎发现打开网站会替换搜索页

今天更新谷歌浏览器发现搜索东西&#xff0c;点击搜索结果网站&#xff0c;打开后的网站页会替换掉当前搜索页&#xff0c;就得点回退&#xff0c;很烦 后来发现不是谷歌浏览器的问题&#xff0c;是搜索引擎的问题&#xff0c;设置下搜索引擎就行 我使用的是bing搜索引擎 勾…

网站如何集成markdown编辑器

收藏(4)Markdown是一种可以使用普通文本编辑器编写的标记语言&#xff0c;通过简单的标记语法&#xff0c;它可以使普通文本内容具有一定的格式。它用简洁的语法代替排版&#xff0c;而不像一般我们用的文字处理软件 Word 等有大量的排版、字体设置。这使得我们能够专心的码字&…

Linux测试网速(linux服务器测试网站,命令行)

第一步&#xff1a;wget https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py 第二步&#xff1a; chmod arx speedtest.py 第三步&#xff1a; sudo mv speedtest.py /usr/local/bin/speedtest 第四步&#xff1a;sudo chown root:root /usr/local…

巧用VS2005解决VS2005网站发布不便问题

关键字:VS2005,网站发布,编译一、问题引入在VS2005网站开发过程中,网站发布问题一直是个问题.VS2005创建的网站有几个默认的目录:App_Code,App_Data,App_Themes........如果是但cs/vb文件,比如UploadFile.cs类UploadFile,这个类文件没有可视的aspx文件,那么这个文件就必须放到A…

各类常见的网站检查工具

一、网站基础查询 1.域名基础信息查询 http://tool.chinaz.com/Ip/Whois.asp 通过在线查询你可以知道自己网站的基本信息&#xff0c;当然很多时候你是清楚自己网站的情况的。但是你不一定知道对手网站的情况。 2.详细的网站历史查询 http://www.archive.org/web/web.php 3.网站…

USTC一个开源下载的网站

QT下载路径&#xff0c;版本5.12.6 http://mirrors.ustc.edu.cn/qtproject/official_releases/qt/5.12/5.12.6/

最新10款精美的免费PSD网站模板下载

这篇文章收集了10款免费的 PSD 网站模板分享给大家&#xff0c;您可以免费下载使用。这些高质量的免费 PSD 网站模板可以让您的工作得心应手&#xff0c;帮助您节省大量的时间和精力。感谢那些优秀的设计师分享他们的劳动成果&#xff0c;让更多的人可以使用他们的创意设计&…

精选30个富有想象力的网站设计作品

在设计网站的时候&#xff0c;有几项事情需要牢记&#xff0c;其中很重要的事情之一就是为设计的品牌选择合适的风格。在这篇文章中&#xff0c;你将发现很多创意的&#xff0c;吸引眼球的网站设计作品&#xff0c;设计师们可通过这些优秀的设计作品来获取创作灵感&#xff0c;…

一个网站直接跳转引起的一些思考

近日看了一个站&#xff0c;网站的界面是这样的。 发现鼠标放上去&#xff0c;都是直接跳转&#xff0c;于是我查看了一下源代码 复制代码<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transit…

IIS6.0asp网站文件上传大小限制和图片上传大小的限制解决方法

win2003的iis6限制了asp的上传文件大小为200k&#xff0c;aspx的上传程序没有影响1、先勾选IIS设置中的选项&#xff1a;IIS服务器属性&#xff0d;&#xff0d;&#xff1e;允许直接编辑配置数据库2、在服务里关闭iis admin service服务.3、找到windows\system32\inesrv\下的m…

用ssl加密apache服务器来建立连接加密网站

2019独角兽企业重金招聘Python工程师标准>>> ssl介绍: SSL&#xff08;Secure Sockets Layer&#xff0c;SSL&#xff09;是一种安全协议&#xff0c;在网景公司&#xff08;Netscape&#xff09;推出首版Web浏览器的同时提出&#xff0c;目的是为网络通信提供安全及…

windows server 2003 发布asp.net2.0网站流程及问题

aaa6263 windows server 2003 发布asp.net2.0网站流程及问题 问题&#xff1a; windows server 2003 发布asp.net2.0网站时&#xff0c;会遇到各种问题&#xff0c;整理如下&#xff0c;以备后用。 流程&#xff1a; 1.安装iis6.0 首先从网上下载iis6.0安装包&#xff0c;然后…