给定 http 链接的源代码中的 Grep 字符串

我想使用 bash 命令行在给定网页的源代码中查找字符串。手动我会像在这些步骤中那样做:

  1. 打开https://stackoverflow.com

  2. cltrl+U(在谷歌浏览器中获取源代码)

  3. cltrl+F 查找字符串

例如,有没有办法使用 bash 命令或任何其他方式使用 python 来做到这一点?


慕仙森
浏览 172回答 4
4回答

FFIVE

这是否符合您的要求?curl -s https://stackoverflow.com | grep "string"

喵喔喔

假设你有机会获得curl和grep后来干脆:bash$ curl http://some-website.com | grep -F some-string

吃鸡游戏

一旦我遇到了从 nagios 网络仪表板解析一些值的情况,用过的 wget将内容保存在文件中( -O 文件名)用于grep从文件中获取所需的值wget --user='username' --password='password' https://nagios/dashboard -O filename

一只名叫tom的猫

您可以使用 curl 或 wget CLI 工具来获取页面,然后只需 grep 结果(或管道到 grep)。$ curl https://stackoverflow.com/questions/54698492/grep-string-in-the-source-code-of-a-given-http-link | grep "string in the source code"&nbsp; % Total&nbsp; &nbsp; % Received % Xferd&nbsp; Average Speed&nbsp; &nbsp;Time&nbsp; &nbsp; Time&nbsp; &nbsp; &nbsp;Time&nbsp; Current&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dload&nbsp; Upload&nbsp; &nbsp;Total&nbsp; &nbsp;Spent&nbsp; &nbsp; Left&nbsp; Speed&nbsp; 0&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp; 0 --:--:-- --:--:-- --:--:--&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; <title>python - Grep string in the source code of a given http link - Stack Overflow</title>&nbsp; &nbsp; &nbsp; &nbsp; <meta name="twitter:title" property="og:title" itemprop="name" content="Grep string in the source code of a given http link" />&nbsp; &nbsp; &nbsp; &nbsp; <meta name="twitter:description" property="og:description" itemprop="description" content="I want to use bash commands line to find a string in the source code of a given web page. Manually I would do it like in those steps:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <link rel="alternate" type="application/atom+xml" title="Feed for question &#39;Grep string in the source code of a given http link&#39;" href="/feeds/question/54698492">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <h1 itemprop="name" class="grid--cell fs-headline1 fl1 ow-break-word"><a href="/questions/54698492/grep-string-in-the-source-code-of-a-given-http-link" class="question-hyperlink">Grep string in the source code of a given http link</a></h1><p>I want to use bash commands line to find a string in the source code of a given web page. Manually I would do it like in those steps:</p>100&nbsp; 102k&nbsp; 100&nbsp; 102k&nbsp; &nbsp; 0&nbsp; &nbsp; &nbsp;0&nbsp; &nbsp;160k&nbsp; &nbsp; &nbsp; 0 --:--:-- --:--:-- --:--:--&nbsp; 159k如果您只想要字符串,请使用 grep -o:$ curl https://stackoverflow.com/questions/54698492/grep-string-in-the-source-code-of-a-given-http-link 2>/dev/null | grep -o "string in the source code"string in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source codestring in the source code
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python