我知道有类似的命令行网络浏览器w3m
lynx
。但我正在寻找一个更简单的工具来打印搜索查询。有点像curl
,但格式更漂亮。
就像我跑步一样https://www.youtube.com/results?search_query=linux
我会得到类似的东西:
Top 3 Best Desktop Linux Distros | 2019 Edition
https://www.youtube.com/watch?v=vZ7nI2im4Yg
_________________________________________________
The Next Ubuntu? - Clear Linux First Impressions
https://www.youtube.com/watch?v=UuCxCLFDfwM
_________________________________________________
The Next Ubuntu? - Clear Linux First Impressions
https://www.youtube.com/watch?v=FUGd99GRAfo
_________________________________________________
简而言之,就是标题和链接
编辑:感谢评论,我做了一些进一步的研究网络抓取并发现这段代码结合使用包wget
中的两个应用程序:html-xml-utils
lynx
link="https://www.youtube.com/results?search_query=linux"
wget "$link" -O- |
hxnormalize -x |
hxselect -i "div." | #in this line I'm missing the proper pattern
lynx -stdin -dump
如果我检查 youtube.com 搜索中显示的标题,我会得到:
<div id="title-wrapper" class="style-scope ytd-video-renderer">
<h3 class="title-and-badge style-scope ytd-video-renderer">
<ytd-badge-supported-renderer class="style-scope ytd-video-renderer" disable-upgrade="" hidden="">
<dom-repeat id="repeat" as="badge" class="style-scope ytd-badge-supported-renderer" style="display: none;"><template></template></dom-repeat>
</ytd-badge-supported-renderer>
<a id="video-title" class="yt-simple-endpoint style-scope ytd-video-renderer" title="What is Linux?" href="/watch?v=zA3vmx0GaO8" aria-l$
What is Linux?
</a>
</h3>
<div id="menu" class="style-scope ytd-video-renderer"></div>
</div>
我不知道要使用什么模式hxselect
来 grep 标题和链接。