1 |
#!/bin/sh |
#!/bin/sh |
2 |
|
|
3 |
# proxy settings (same as in firebird) |
# proxy settings (same as in firebird) |
4 |
fping proxy && export http_proxy=http://proxy:8080 |
fping -q proxy && export http_proxy=http://proxy:8080 || |
5 |
|
fping -q proxy.lan && export http_proxy=http://proxy.lan:8080 |
6 |
# user agent (same as in firebird) |
# user agent (same as in firebird) |
7 |
ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040506 Firefox/0.8" |
ua="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040506 Firefox/0.8" |
8 |
cookie_file="cookie.txt" |
cookie_file="cookie.txt" |
10 |
# wait between pages |
# wait between pages |
11 |
export wait=120 |
export wait=120 |
12 |
|
|
13 |
|
if [ ! -z "$http_proxy" ] ; then |
14 |
|
echo "Using proxy $http_proxy" |
15 |
|
fi |
16 |
|
|
17 |
if [ -z "$1" ] ; then |
if [ -z "$1" ] ; then |
18 |
echo "Usage: $0 ISBN" |
echo "Usage: $0 ISBN" |
32 |
grep -l 'This is only a preview of the full book' * | xargs -i rm {} |
grep -l 'This is only a preview of the full book' * | xargs -i rm {} |
33 |
fi |
fi |
34 |
|
|
35 |
isbn=`echo $1 | sed 's/-//g'` |
isbn=`echo $1 | sed 's/-//g' | tr '[a-z]' '[A-Z]'` |
36 |
|
|
37 |
function mirror() { |
function mirror() { |
38 |
|
|
71 |
fi |
fi |
72 |
|
|
73 |
wget -q -p -nH -nc -k -t 1 -U "$ua" --cookies=off --header="$cookie" $url |
wget -q -p -nH -nc -k -t 1 -U "$ua" --cookies=off --header="$cookie" $url |
74 |
|
perl -e '$t=rand($ENV{wait} || 120);print "sleep for $t sec.\n"; sleep($t);' |
75 |
|
|
|
perl -e '$t=rand($ENV{wait} || 30);print "sleep for $t sec.\n"; sleep($t);' |
|
76 |
} |
} |
77 |
|
|
78 |
function geturl() { |
function geturl() { |
84 |
-e 's/\&srchText=//' \ |
-e 's/\&srchText=//' \ |
85 |
-e 's/open=false/open=true/' | \ |
-e 's/open=false/open=true/' | \ |
86 |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
87 |
grep $2 | \ |
grep -i "xmlid=[0-9A-Za-z\-][0-9A-Za-z\-]*" | \ |
88 |
grep -v "$2/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" | \ |
grep -vi "xmlid=[0-9A-Za-z\-]*/[0-9][0-9][0-9][0-9][0-9][0-9][0-9]" | \ |
89 |
sort -u >> in |
sort -u >> in |
90 |
} |
} |
91 |
|
|
126 |
} |
} |
127 |
|
|
128 |
echo -n > in |
echo -n > in |
129 |
mirror "http://safari.oreilly.com/?XmlId=$isbn" |
mirror "http://safari.oreilly.com/$isbn" |
130 |
echo |
echo |
131 |
|
|
132 |
echo "extract URLs from first page..." |
file=`ls *index.html?XmlId=*` |
133 |
geturl "index.html?XmlId=$isbn" $isbn |
isbn=`echo $file | cut -d= -f2` |
134 |
|
echo "extract URLs from first page $file... [$isbn]" |
135 |
|
geturl $file $isbn |
136 |
uniqurl |
uniqurl |
137 |
|
|
138 |
mirror_in |
mirror_in |