为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕仙森 2021-11-09 15:18:24
我想使用 bash 命令行在给定网页的源代码中查找字符串。手动我会像在这些步骤中那样做:打开https://stackoverflow.comcltrl+U(在谷歌浏览器中获取源代码)cltrl+F 查找字符串例如,有没有办法使用 bash 命令或任何其他方式使用 python 来做到这一点?
查看完整描述

4 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

这是否符合您的要求?

curl -s https://stackoverflow.com | grep "string"


查看完整回答
反对 回复 2021-11-09
?
喵喔喔

TA贡献1735条经验 获得超5个赞

假设你有机会获得curlgrep后来干脆:

bash$ curl http://some-website.com | grep -F some-string


查看完整回答
反对 回复 2021-11-09
?
吃鸡游戏

TA贡献1829条经验 获得超7个赞

一旦我遇到了从 nagios 网络仪表板解析一些值的情况,

  • 用过的 wget

  • 将内容保存在文件中( -O 文件名)

  • 用于grep从文件中获取所需的值

    wget --user='username' --password='password' https://nagios/dashboard -O filename


查看完整回答
反对 回复 2021-11-09
?
一只名叫tom的猫

TA贡献1906条经验 获得超2个赞

您可以使用 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"

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0        <title>python - Grep string in the source code of a given http link - Stack Overflow</title>

        <meta name="twitter:title" property="og:title" itemprop="name" content="Grep string in the source code of a given http link" />

        <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:

            <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">

                    <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  102k  100  102k    0     0   160k      0 --:--:-- --:--:-- --:--:--  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 code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code

string in the source code


查看完整回答
反对 回复 2021-11-09
  • 4 回答
  • 0 关注
  • 157 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信