首页 > 解决方案 > 获取洋葱站点标题的 Bash 脚本

问题描述

我正在编写一个 bash 脚本,它给出了一个“.onion”站点列表和每个站点的 cURLs 页面标题,然后在新的文本文件中以以下格式输出:

“页面标题” - “xxxxxx.onion”

这是我到目前为止的代码,但我在如何实现我的目标方面遇到了困难。

#
#
echo '必须为 grep 安装 PCRE'
回声''
#
#
# 检查洋葱路由器连接
#
RESP1="$(curl --socks5-hostname localhost:9150 -s 'https://check.torproject.org')"
#
# 回声 $RESP1 # 调试
RESP2=$(echo "$RESP1" | grep -m 1 "恭喜" | xargs)
# 回声 $RESP2 # 调试
if [ "$RESP2"="恭喜。此浏览器配置为使用 Tor。" ]
  然后
        echo "连接到洋葱路由器"
    别的
        echo "连接洋葱路由器失败"
      1号出口
菲
# 抓取网站的原始 html
RESP3="$(xargs -n 1 curl --socks5-hostname localhost:9150 -so - < slist.txt)"
# RESP3="$(curl --socks5-hostname localhost:9150 "$site" -so - )" #OLD
# grep 标题
RESP4=$(echo "$RESP3" | grep -iPo '(?<=<title>)(.*)(?=</title>)')
#
回声 $RESP4

标签: bashcurltor

解决方案


看来你快到了。
如果将脚本的最后一部分替换为:

cat slist.txt \
| while read -r url; do
    # Grab raw html of site
    RESP3="$(curl --socks5-hostname localhost:9150 -so - $url)"
    # Grep for title
    RESP4=$(echo "$RESP3" | grep -iPo '(?<=<title>)(.*)(?=</title>)')
    #
    echo "$RESP4 - $url"
done

只需将脚本的输出重定向到文本文件即可。这是你的目标还是我错过了什么?


推荐阅读