【发布时间】:2016-03-25 05:15:20
【问题描述】:
我正在尝试通过以下链接抓取在 docker hub 中找到的所有存储库名称:https://hub.docker.com/search/?q=*&page=1&isAutomated=0&isOfficial=1&pullCount=0&starCount=0
我感兴趣的 HTML 标签是:
<div class="RepositoryListItem__repoName___3iIWs" data-reactid=".s0zyncta0w.1.2.1.0.0.$4lexnz/overtime.0.0.1.0">4lexnz/overtime</div>
每个存储库的 data-reactid 总是不同的。
我正在使用 Bash,并希望在每个包含 class="RepositoryListItem__repoName___3iIWs" 的 div 的 div 标签之间查找文本。有人可以帮我构建一个正则表达式和命令链来在 bash 中执行此操作吗?
到目前为止我有:
content=$(curl -L 'https://hub.docker.com/search/?q=*&page=1&isAutomated=0&isOfficial=0&pullCount=0&starCount=0')
echo $content | grep -oP '(?<=<div class="RepositoryListItem__repoName___3iIWs").*?(?= </div>)'
但这根本不返回任何东西。 $content 的值是正确的,所以它是最后一个没有做我想做的事情的 grep。有人可以帮忙吗?谢谢!
【问题讨论】: