#!/bin/bash
domainname="http://www.cvedetails.com//product-list/vendor_id-"
echo "before while"
x=11614
while ((${x}>0))
do
wget -O result.html $domainname${x}
vendor=`cat result.html|grep '<title>'|cut -d '>' -f2|cut -d ':' -f1`
# 插入数据库
resultrow="insert into t_software_vendor select ${x},'${vendor}' from dual;"
echo $resultrow
mysql -h 192.168.3.93 -phuawei virus -e"${resultrow}"
echo $resultrow>>result.txt
echo $resultrow
count=`cat result.html|grep 'Total number of products found ='|cut -d ' ' -f 7|cut -d '&' -f1`
let "page=${count}/50+1"
while ((${page}>0))
do
wget -O result.html "$domainname${x}/page-${page}"
cat result.html|tr -d '\n'|sed 's/<a href="http:\/\/www.cvedetails.com\/product/@<a href="http:\/\/www.cvedetails.com\/product/g'|tr '@' '\n'|grep '<a href="http://www.cvedetails.com/product' >final.html
row=`wc -l final.html|cut -d ' ' -f1`
while ((${row}>0))
do
productid=`tail -${row} final.html|tr -d '\n'|cut -d '/' -f5`
productname=`tail -${row} final.html|tr -d '\n'|cut -d '>' -f2 |cut -d '<' -f1`
producttype=`tail -${row} final.html|tr -d '\n'|cut -d '>' -f13|cut -d '<' -f1`
# 插入数据库
resultrow="insert into t_software_product select ${x},${productid},trim('${productname}'),trim('${producttype}') from dual;"
echo $resultrow
mysql -h 192.168.3.93 -phuawei virus -e"${resultrow}"
echo $resultrow>>result.txt
echo $resultrow
#控制行数
let "row=${row}-1"
done
#控制行数
let "page=${page}-1"
done
let "x=${x}-1"
done
echo done