Bash 查找坏链接
我有一个关于6k链接的列表。我需要浏览每一页,看看它所指向的页面是否包含特定的单词Bash 查找坏链接,bash,shell,Bash,Shell,我有一个关于6k链接的列表。我需要浏览每一页,看看它所指向的页面是否包含特定的单词 最简单的方法是什么?您可以编写一个selenium脚本来访问每个url,然后检查这些单词是否出现在这些页面上。您可以编写一个selenium脚本来访问每个url,然后检查这些单词是否出现在这些页面上。不是最快的方法,但首先想到的是: #!bin/bash while read url do content=$(wget $url -q -O -) # and here you can chec
最简单的方法是什么?您可以编写一个selenium脚本来访问每个url,然后检查这些单词是否出现在这些页面上。您可以编写一个selenium脚本来访问每个url,然后检查这些单词是否出现在这些页面上。不是最快的方法,但首先想到的是:
#!bin/bash
while read url
do
content=$(wget $url -q -O -)
# and here you can check
# if there are matches in $content
done < "links.txt"
#!bin/bash
读取url时
做
content=$(wget$url-q-O-)
#在这里你可以查一下
#如果$content中有匹配项
完成<“links.txt”
不是最快的方法,而是第一个:
#!bin/bash
while read url
do
content=$(wget $url -q -O -)
# and here you can check
# if there are matches in $content
done < "links.txt"
#!bin/bash
读取url时
做
content=$(wget$url-q-O-)
#在这里你可以查一下
#如果$content中有匹配项
完成<“links.txt”
脏溶液:
#! /bin/bash
while read link ; do
wget -qO- "$link" | grep -qiFf words.lst - && echo "$link"
done < links.lst > found.lst
#/bin/bash
读链接时;做
wget-qO-“$link”| grep-qiFf words.lst-&&echo“$link”
完成found.lst
链接应保存在Links.lst
中,每行一个链接。单词应保存在Words.lst中,每行一个单词。脏溶液:
#! /bin/bash
while read link ; do
wget -qO- "$link" | grep -qiFf words.lst - && echo "$link"
done < links.lst > found.lst
#/bin/bash
读链接时;做
wget-qO-“$link”| grep-qiFf words.lst-&&echo“$link”
完成found.lst
链接应保存在Links.lst
中,每行一个链接。单词应保存在Words.lst中,每行一个单词。我为您创建了一个:
创建一个名为words.txt的文件,其中包含要检查的单词,并用空格分隔
创建一个名为links.url的文件,其中包含一个url列表,以便每行检查一个url
创建一个名为crawler.sh的文件,其中包含以下脚本:
#!/bin/bash
# A file with a list of urls one per line
LINKS_FILE="links.url"
# A file with a list of words separed by spaces
WORDS_FILE="words.txt"
HTTP_CLIENT="/usr/bin/wget -O - "
rm -f /tmp/temp.html
for link in `cat "$LINKS_FILE"`
do
# Downloading page
echo "--"
echo "Scanning link: $link"
$HTTP_CLIENT "$link" > /tmp/temp.html
if [ $? -ne 0 ]
then
echo "## Problem downloading resource $link" 1>&2
continue
fi
# Checking words
for word in `cat "$WORDS_FILE"`
do
echo "Checking for the word \"$word\"..."
if [ "x`grep -i $word /tmp/temp.html`" != "x" ]
then
echo "** The word $word is found into the uri \"$link\""
continue 2
fi
done
echo "** No words found into \"$link\""
echo "--"
echo
done
rm -f /tmp/temp.html
运行包装器。我为您创建了一个:
创建一个名为words.txt的文件,其中包含要检查的单词,并用空格分隔
创建一个名为links.url的文件,其中包含一个url列表,以便每行检查一个url
创建一个名为crawler.sh的文件,其中包含以下脚本:
#!/bin/bash
# A file with a list of urls one per line
LINKS_FILE="links.url"
# A file with a list of words separed by spaces
WORDS_FILE="words.txt"
HTTP_CLIENT="/usr/bin/wget -O - "
rm -f /tmp/temp.html
for link in `cat "$LINKS_FILE"`
do
# Downloading page
echo "--"
echo "Scanning link: $link"
$HTTP_CLIENT "$link" > /tmp/temp.html
if [ $? -ne 0 ]
then
echo "## Problem downloading resource $link" 1>&2
continue
fi
# Checking words
for word in `cat "$WORDS_FILE"`
do
echo "Checking for the word \"$word\"..."
if [ "x`grep -i $word /tmp/temp.html`" != "x" ]
then
echo "** The word $word is found into the uri \"$link\""
continue 2
fi
done
echo "** No words found into \"$link\""
echo "--"
echo
done
rm -f /tmp/temp.html
运行包装程序。你是试图获取电子邮件地址的垃圾邮件发送者吗?:-)哈哈,不,我必须找到垃圾链接!:-)你是试图获取电子邮件地址的垃圾邮件发送者吗?:-)哈哈,不,我必须找到垃圾链接!:-)好的,它现在正在运行,而且运行得很好!让我们看看进展如何+1,但不需要bash。也可以是#/bin/sh
。好的,它现在正在运行,运行得很好!让我们看看进展如何+1,但不需要bash。也可以是#/bin/sh
。在读取-r链接时,不要使用for
来迭代cat
:;做完成<“$LINKS\u文件”
if[“x…”!=“x”]
是古语,您可以直接测试grep
:if grep-qsi“$word”/tmp/temp.html`(选项可能因grep
版本而异)。您应该使用mktemp
或tempfile
创建临时文件。嵌套循环将比公认答案的grep-f
慢@Dennis Williamson谢谢你的建议。我尝试编写可移植的ShellScript,它可能会在许多Unice上运行,无需修改。无论如何,谢谢你!我的建议中没有什么特别不可移植的。您可以轻松地使if grep
更具可移植性:if grep-i“$word”filename>/dev/null>&2
。您可以对mktemp
和tempfile
执行存在性检查,并返回到固定名称。x
技术仅适用于真正古老的伯恩贝壳。在读取-r链接时,不要使用for
迭代cat
:;做完成<“$LINKS\u文件”
if[“x…”!=“x”]
是古语,您可以直接测试grep
:if grep-qsi“$word”/tmp/temp.html`(选项可能因grep
版本而异)。您应该使用mktemp
或tempfile
创建临时文件。嵌套循环将比公认答案的grep-f
慢@Dennis Williamson谢谢你的建议。我尝试编写可移植的ShellScript,它可能会在许多Unice上运行,无需修改。无论如何,谢谢你!我的建议中没有什么特别不可移植的。您可以轻松地使if grep
更具可移植性:if grep-i“$word”filename>/dev/null>&2
。您可以对mktemp
和tempfile
执行存在性检查,并返回到固定名称。x
技术仅适用于真正古老的伯恩贝壳。