-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbiquge.pl
147 lines (137 loc) · 4.17 KB
/
biquge.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Perl Script for biquge.la
use LWP::Simple qw(getstore);
use Encode;
#Global Parameters:
$bookid=61;
#Grab Table of Content Page
getstore( "http://www.biquge.la/book/$bookid", "toc.html" );
print "Table of Content Download Completed\n";
#Create .ncx Table File
open (tocsource, "<", "toc.html") || die ("Could not open content file");
open (toctarget, ">", "toc.ncx") || die ("Could not create content file");
print toctarget (" \<docTitle\>
\<text\>title of book\<\/text\>
\<\/docTitle\>
\<navMap\>");
#Read Chapter num & name from Content
$j=0;
while (<tocsource>){
if(/\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>/){
@num = (@num, $1, $3, $5);
@name = (@name, $2, $4, $6);
$j = $j + 3;}
elsif(/\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>/){
@num = (@num, $1, $3);
@name = (@name, $2, $4);
$j = $j + 2;}
elsif(/\<dd\>\<a href\=\"(.*)\.html\"\>(.*?)\<\/a\>\<\/dd\>/){
@num = (@num, $1);
@name = (@name, $2);
$j = $j + 1;}
}
print ("$j\n");
close(tocsource);
#Processing Content
$i++;
$num = shift @num;
$name = shift @name;
print $name;
while(@num){
if($i>0){
getstore( "http:\/\/www\.biquge\.la\/book\/$bookid\/$num.html", "$i.html" );
print "$i\n";
open (htmlsource, "<", "$i.html") || redo;
open (htmlresult, ">$i.xhtml");
while (<htmlsource>){
if(/\<div id\=\"content\"\>(.*)\<\/div\>/){
$temp = encode("utf-8",decode("gbk",$1));
$temp =~ s/\ \;\ \;\ \;\ \;\;//g;
$temp =~ s/\ \;\ \;\ \;\ \;/
\<p\>\ \; \ \; /g;
$temp =~ s/\<br.*?\>\<br.*?\>/\<\/p\>\n/g;
$temp =~ s/rì/日/g;
$temp =~ s/chūn/春/g;
$temp =~ s/sè/色/g;
$temp =~ s/xìng/性/g;
$temp =~ s/dú lì/独立/g;
$temp =~ s/shè/射/g;
$temp =~ s/yīn/阴/g;
$temp =~ s/zhōng yāng/中央/g;
$temp =~ s/cāo/操/g;
$temp =~ s/sāo/骚/g;
print htmlresult ("<\?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"\?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title></title>
</head>
<body>");
print htmlresult $temp;
print htmlresult ("\<\/body\>
\<\/html\>");}
}
close (htmlsource);
close (htmlresult);
}
print toctarget ("
\<navPoint id\=\"navPoint\-$i\" playOrder\=\"$i\"\>
\<navLabel\>
\<text\>$name\<\/text\>
\<\/navLabel\>
\<content src\=\"Text\/$i.xhtml\"\/\>
\<\/navPoint\>");
$i++;
$num = shift @num;
$name = shift @name;
print $name;
next;
}
#Final Chapter
getstore( "http:\/\/www\.biquge\.la\/book\/$bookid\/$num.html", "$i.html" );
print "$i\n";
open (htmlsource, "<", "$i.html") || die ("Could not open file");
open (htmlresult, ">$i.xhtml");
while (<htmlsource>){
if(/\<div id\=\"content\"\>(.*)\<\/div\>/){
$temp = encode("utf-8",decode("gbk",$1));
$temp =~ s/\ \;\ \;\ \;\ \;\;//g;
$temp =~ s/\ \;\ \;\ \;\ \;/
\<p\>\ \; \ \; /g;
$temp =~ s/\<br.*?\>\<br.*?\>/\<\/p\>\n/g;
$temp =~ s/rì/日/g;
$temp =~ s/chūn/春/g;
$temp =~ s/sè/色/g;
$temp =~ s/xìng/性/g;
$temp =~ s/dú lì/独立/g;
$temp =~ s/shè/射/g;
$temp =~ s/yīn/阴/g;
$temp =~ s/zhōng yāng/中央/g;
$temp =~ s/cāo/操/g;
$temp =~ s/sāo/骚/g;
print htmlresult ("<\?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"no\"\?>
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<title></title>
</head>
<body>");
print htmlresult $temp;
print htmlresult ("\<\/body\>
\<\/html\>");}
}
close (htmlsource);
close (htmlresult);
print toctarget ("
\<navPoint id\=\"navPoint\-$i\" playOrder\=\"$i\"\>
\<navLabel\>
\<text\>$name\<\/text\>
\<\/navLabel\>
\<content src\=\"Text\/$i.xhtml\"\/\>
\<\/navPoint\>");
#End of Table
print toctarget ("
\<\/navMap\>
\<\/ncx\>");
close (toctarget);