我在试着抓取一些网站。我已经寻找了其他方法,并放弃了所有不必要的资源请求,但这对我来说仍然太慢了(大约8-9秒)。
我在我发现的一篇博客文章中使用了并行gnu,但是似乎虽然进程是活动的,但它们并不是并行爬行的,因为一个实例的总执行时间仍然是相同的。
最简单、最实用的方法是什么?
发布于 2016-12-05 04:09:59
你能适应这个吗:https://www.gnu.org/software/parallel/man.html#EXAMPLE:-Breadth-first-parallel-web-crawler-mirrorer
#!/bin/bash
# E.g. http://gatt.org.yeslab.org/
URL=$1
# Stay inside the start dir
BASEURL=$(echo $URL | perl -pe 's:#.*::; s:(//.*/)[^/]*:$1:')
URLLIST=$(mktemp urllist.XXXX)
URLLIST2=$(mktemp urllist.XXXX)
SEEN=$(mktemp seen.XXXX)
# Spider to get the URLs
echo $URL >$URLLIST
cp $URLLIST $SEEN
while [ -s $URLLIST ] ; do
cat $URLLIST |
parallel lynx -listonly -image_links -dump {} \; \
wget -qm -l1 -Q1 {} \; echo Spidered: {} \>\&2 |
perl -ne 's/#.*//; s/\s+\d+.\s(\S+)$/$1/ and do { $seen{$1}++ or print }' |
grep -F $BASEURL |
grep -v -x -F -f $SEEN | tee -a $SEEN > $URLLIST2
mv $URLLIST2 $URLLIST
done
rm -f $URLLIST $URLLIST2 $SEENhttps://stackoverflow.com/questions/40953975
复制相似问题