Grep строка в исходном коде данной ссылки http - PullRequest
0 голосов
/ 14 февраля 2019

Я хочу использовать командную строку bash, чтобы найти строку в исходном коде данной веб-страницы.Вручную я бы сделал это, как в этих шагах:

  1. Открыть https://stackoverflow.com
  2. cltrl + U (чтобы получить исходный код в Google Chrome)
  3. cltrl +F, чтобы найти строку

Есть ли способ сделать это, используя команды bash или любой другой способ, например, с python?

Ответы [ 4 ]

0 голосов
/ 12 марта 2019

как только я попал в ситуацию для анализа какого-либо значения с веб-панели nagios,

  • использовал wget
  • сохранил содержимое в файле (-O имя файла)
  • используется grep для получения желаемого значения из файла

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

0 голосов
/ 14 февраля 2019

Вы можете использовать инструменты CLI curl или wget, чтобы получить страницу, а затем просто получить результат (или передать в grep).

$ curl /11978298/grep-stroka-v-ishodnom-kode-dannoi-ssylki-http | 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 /11978298/grep-stroka-v-ishodnom-kode-dannoi-ssylki-http 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
0 голосов
/ 14 февраля 2019

Делает ли это то, что вы просите?

curl -s https://stackoverflow.com | grep "string"
0 голосов
/ 14 февраля 2019

Если у вас есть доступ к curl и grep, то просто:

bash$ curl http://some-website.com | grep -F some-string
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...