Recently, I had a program to automatically capture data from some BT websites and post it to my own forum. It worked better after a few months of trial, now the source code is published for reference by Perl enthusiasts. QQ is 2637663 and we welcome Perl enthusiasts to communicate with each other.
Consists of several programs
Readcokie. pl get the cookie of the host to be uploaded once. It is permanently saved on the host.
Fatie. pl captures the source host data and automatically posts the data to the target host.
History. Log saves captured data
User.txt user list used for posting
..........
The procedure is as follows:
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/123 ');
Use http: cookies;
Use http: Request: Common QW (post );
Use lwp: useragent;
$ UA = lwp: useragent-> new;
Open (file, 'd:/bin/posttools/automatic post/btarea top post/cc8.cnsuk.net Sinha myth/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 // Automatic posting // top post in the btarea // cc8.cnsuk.net Xinsha + myth/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 ";
# Initialization parameters
$ N_file = 'd:/bin/posttools/automatic post/btarea top post/cc8.cnsuk.net shinshaga myth //';
### Temporary seed file address
# Define the address @ URL @ postid @ bankuainame
$ Hhttp = 'HTTP: // cc8.cnsuk.net ';
$ URL [0] = 'HTTP: // cc9.cnsuk.net/forum-2944-2.html ';
$ Postid [0] = '13 ';
$ Bankuainame [0] = "$ hhttp-game ";
$ URL [1] = 'HTTP: // cc9.cnsuk.net/forum-2944-1.html ';
$ Postid [1] = '13 ';
$ Bankuainame [1] = "$ hhttp-game ";
$ URL [2] = 'HTTP: // cc9.cnsuk.net/forum-2905-2.html ';
$ Postid [2] = '13 ';
$ Bankuainame [2] = "$ hhttp-game ";
$ URL [3] = 'HTTP: // cc9.cnsuk.net/forum-2905-1.html ';
$ Postid [3] = '13 ';
$ Bankuainame [3] = "$ hhttp-game ";
While (1 ){
For ($ u = 0; $ U <=$ # URL; $ U ++ ){
$ Htms = '';
$ Res = $ UA-> get ($ URL [$ u]);
$ Htms = $ res-> content;
Print "get $ bankuainame [$ u] Forum data/N ";
# Extract useful data after obtaining
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] [dedicated patch for the latest BT game patch release] [temporary release] </a> <SPAN class =" lighttxt ">
# If (m {^ <a href = "(viewthread/. php /? Tid =) (/d +) &. *> (. *) </a> }){
If (m {^ <a href = "(thread/-) (/D *) (/-/D */. html)". *?> (.*?) </A> }){
Push (@ link, $1. $2. $3 );
Push (@ tid, $2 );
Push (@ TTI, $4 );
}
}
}
Print "pick out useful data $ # Link/N ";
# History
Open (file, $ n_file. 'data/history. log ');
@ History = ();
@ History = <File>;
Close file;
# User records
Open (file, $ n_file. 'data/user.txt ');
@ Usertxt = ();
@ Usertxt = <File>;
Close file;
# Submit records
Print "read user information/N ";
# Check whether the post is in history. If not, post the post.
$ Chazhao = 0; # whether 0 is found or not
For ($ x = 0; $ X <=$ # tid; $ X ++ ){
For ($ A = 0; $ A <=$ # History; $ A ++ ){
If ($ history [$ A] ==$ TID [$ X]) {
$ A =$ # History + 1;
$ Chazhao = 1;
}
}
Print "post $ TTI [$ X] $ TID [$ X] Find the flag $ chazhao/N ";
If ($ chazhao = 0) {# post if the history does not exist
# Obtain the content of the source post
$ Url = "$ hhttp/$ link [$ X]";
$ Res = $ UA-> get ($ URL );
$ Htmls = $ res-> content;
# Open (file, '> D:/bin/posttools/automatic post/btarea top post/bbs.btpig.com pig Park/bin/temp. log'); # debug
# Print file $ htmls; # debug
# Close file; # debug
@ Html = ();
@ Html = Split (// n/, $ htmls );
@ Torlink = ();
@ Tortid = ();
@ Torxylink = ();
@ Tortti = ();
$ ZD = 0;
# Getting all seed addresses
For (@ html ){
# <A href = "viewthread. php? Tid = 645515 & extra = Page % 3d1 "style =" font-weight: bold; color: blue "> [02.02] [original] [us] [World War II] [World War five] [DVDRip] [6.1 GB] English Subtitles </a>
# <A href = "attachment. php? Aid = 26721 "target =" _ blank "class =" bold "> complete set of heroes★Cc8cnsuk.net shinshaga myth★Vitas★. Torrent </a> (, 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;
}
}
# Post only when the seed file is found; otherwise, do not post
If ($ ZD = 1 ){
$ Userc = int (rand ($ # usertxt); # select the user
Chomp ($ usertxt [$ userc]);
($ User, $ pass) = Split (//,/, $ usertxt [$ userc]);
Print "decides user $ userc post/N ";
# Getting Seeds
@ Torxylink = ();
For ($ f = 0; $ f <=$ # tortid; $ f ++ ){
$ Err = 0;
$ Url = "$ hhttp/$ torlink [$ F]";
$ Res = $ UA-> get ($ URL, Referer => $ hhttp ,);
Print "the seed is obtained successfully. Start to upload the seed/N ";
If ($ res-> is_success ){
$ Torrent = $ res-> content;
$ Filename = "$ n_file". "torrent // temp/. torrent ";
Open (file2, "> $ FILENAME ";
Binmode (file2 );
Print file2 $ torrent;
Close file2;
# Uploading Seeds
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 /',);
# Obtain the upload target seed address
# <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) {# continue to upload if there are no errors for five times
$ Err ++;
Goto W1;
}
}
Last W1;
}
}
Print "seed uploaded/N ";
# Sleep 3;
}
# Splitting source posts
$ Zzdaot = 0;
$ Zzdaow = 0;
For ($ S = 0; $ S <=$ # HTML; $ s ++ ){
# Find the post Header
If ($ zzdaot = 0 ){
If ($ HTML [$ S] = ~ M/<Table width = "95%" border = "0" cellspacing = "0" cellpadding = "0 "/){
$ Tou = $ S + 39; # + 5 is the header offset.
$ Zzdaot = 1;
}
} Elsif ($ zzdaow = 0 ){
If ($ HTML [$ S] = ~ M/<Table width = "95%" border = "0" cellspacing = "0" cellpadding = "0 "/){
$ Wei = $ s-30; # tail offset
$ Zzdaow = 1;
}
}
}
# If only the header is found and the tail is not found, the tail offset is 30;
If ($ zzdaot = 1 and $ zzdaow = 0 ){
$ Wei = $ tou + 30;
}
# Getting all image addresses
Print "get all image addresses/N ";
@ Imgh = ();
For ($ B = $ TOU; $ B <= $ Wei; $ B ++ ){
@ Imgh = Split (//, $ HTML [$ B]);
For ($ J = 0; $ J <=$ # imgh; $ J ++ ){
# 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';} "onmouseover =" 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 ';} "onclick =" If (! This. resized) {return true;} else {window. Open ('HTTP: // callback);} "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 "Preparing to post data merging/N ";
$ Constor = '';
# Merge seed addresses
For ($ B = 0; $ B <=$ # torxylink; $ B ++ ){
$ Constor. = "<br> torxylink [$ B] <br> ";
}
@ Torxylink = ();
# Merge Image addresses
For ($ B = 0; $ B <=$ # IMG; $ B ++ ){
$ Constor. = "<br> $ IMG [$ B] <br> ";
}
@ IMG = ();
# Merge the data to be sent
$ 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> the data comes from $ hhttp/$ link [$ X] <br> ";
##### It's really not easy to post after I start posting.
$ 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];
# Start posting
Print "start posting/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 "post $ TTI [$ X] $ TID [$ X] records historical completion/N ";
Open (file, ">>$ n_file". 'data/history. log'); # record the post
Print file "$ TID [$ X]/n ";
Close file;
}
Print "=================================$ bankuainame [$ u] ================ ===============/N ";
$ Chazhao = 0;
}
}
Print "Sleep 1200 seconds/N ";
Sleep 1200;
}