1 |
#!/bin/sh |
2 |
|
3 |
#export http_proxy=http://proxy:8080 |
4 |
|
5 |
if [ -z "$1" ] ; then |
6 |
echo "Usage: $0 ISBN" |
7 |
exit 1 |
8 |
fi |
9 |
|
10 |
isbn=$1; |
11 |
|
12 |
wait=10 |
13 |
|
14 |
isbn2=`echo $isbn | sed 's/-//g'` |
15 |
|
16 |
function mirror() { |
17 |
wget -p -nH -nc -k \ |
18 |
--random-wait --wait=$wait -t 0 \ |
19 |
--load-cookies=/home/dpavlin/.phoenix/default/g6b45nt6.slt/cookies.txt \ |
20 |
-U "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031206 Firebird/0.7" \ |
21 |
$1 |
22 |
|
23 |
# -D safari.oreilly.com \ |
24 |
# -A 0-201-41975-0 \ |
25 |
} |
26 |
|
27 |
function geturl() { |
28 |
hindent -s $1 | grep -i href | grep mode=[st][eo]c | \ |
29 |
sed -e 's/^.*<a.*href="//i' \ |
30 |
-e 's/".*//' -e 's/amp;//g' \ |
31 |
-e 's,^[^\?]*\?,http://safari.oreilly.com/,' \ |
32 |
-e 's/#$//' \ |
33 |
-e 's/\&srchText=//' \ |
34 |
-e 's/open=false/open=true/' | \ |
35 |
grep '&s=1&b=1&f=1&t=1&c=1&u=1&r=&o=1' | \ |
36 |
grep $2 | \ |
37 |
sort -u >> in |
38 |
} |
39 |
|
40 |
function uniqurl() { |
41 |
mv in in.tmp |
42 |
grep -v 'view=[A-Z]' in.tmp | sort -u > in |
43 |
grep 'view=[A-Z].*/index' in.tmp | sort -u >> in |
44 |
} |
45 |
|
46 |
function checklogin() { |
47 |
if grep 'promo.asp' index.html* >/dev/null ; then |
48 |
echo "WARNING: safari seems to logunt you as user. Aborting." |
49 |
exit 1 |
50 |
fi |
51 |
} |
52 |
|
53 |
echo > in |
54 |
mirror "http://safari.oreilly.com/?XmlId=$isbn" |
55 |
|
56 |
echo "extract URLs from first page..." |
57 |
geturl "index.html?XmlId=$isbn" $isbn |
58 |
uniqurl |
59 |
|
60 |
mirror "-i in" |
61 |
checklogin |
62 |
|
63 |
echo -n "extracting URLs [1]" |
64 |
ls index.html* | while read file ; do |
65 |
echo -n "." |
66 |
geturl $file $isbn |
67 |
done |
68 |
echo |
69 |
|
70 |
uniqurl |
71 |
|
72 |
mirror "-i in" |
73 |
checklogin |
74 |
|
75 |
echo > in |
76 |
echo -n "extracting URLs [2]" |
77 |
ls index.html* | while read file ; do |
78 |
echo -n "." |
79 |
geturl $file $isbn |
80 |
done |
81 |
|
82 |
uniqurl |
83 |
|
84 |
mirror "-i in" |
85 |
checklogin |
86 |
|
87 |
# convert links in html |
88 |
bn=`basename $0` |
89 |
dir=`echo $0 | sed "s/$bn$//"` |
90 |
ls index.html* | xargs -i $dir/filter.pl {} |
91 |
mkdir orig |
92 |
mv index.html* orig/ |
93 |
|