Python 给定http链接的源代码中的Grep字符串
我想使用bash命令行在给定网页的源代码中查找字符串。我会手动执行以下步骤: 打开 cltrl+U在google chrome中获取源代码 cltrl+F以查找字符串Python 给定http链接的源代码中的Grep字符串,python,bash,shell,command-line,Python,Bash,Shell,Command Line,我想使用bash命令行在给定网页的源代码中查找字符串。我会手动执行以下步骤: 打开 cltrl+U在google chrome中获取源代码 cltrl+F以查找字符串 有没有一种方法可以使用bash命令或python中的任何其他方法来实现这一点?假设您可以访问curl和grep,那么只需: bash$ curl http://some-website.com | grep -F some-string 假设您可以访问curl和grep,那么只需: bash$ curl http://some-
有没有一种方法可以使用bash命令或python中的任何其他方法来实现这一点?假设您可以访问curl和grep,那么只需:
bash$ curl http://some-website.com | grep -F some-string
假设您可以访问curl和grep,那么只需:
bash$ curl http://some-website.com | grep -F some-string
您可以使用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 'Grep string in the source code of a given http link'" 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
您可以使用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 'Grep string in the source code of a given http link'" 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
这符合你的要求吗
curl -s https://stackoverflow.com | grep "string"
这符合你的要求吗
curl -s https://stackoverflow.com | grep "string"
有一次我需要从nagios web dashboard解析一些值 你用过wget吗 将内容保存在文件中-O文件名 使用grep从文件中获取所需的值 wget-user='username'-password='password'https://nagios/dashboard -O文件名
有一次我需要从nagios web dashboard解析一些值 你用过wget吗 将内容保存在文件中-O文件名 使用grep从文件中获取所需的值 wget-user='username'-password='password'https://nagios/dashboard -O文件名
Beautiful soup是一个python模块,它可能具有您所需要的功能。请注意,html上的grep可能无法提供您所希望的一致结果,这取决于您的字符串及其特定的源代码。如果可能的话,了解你的数据。@MitchelPaulin你能给我推荐你知道的任何模块吗?@PaulHodges哦,好的。。还有别的选择吗?漂亮的汤?Beautiful soup是一个python模块,它可能具有您所需要的功能。请注意,html上的grep可能无法提供您所希望的一致结果,这取决于您的字符串及其特定的源代码。如果可能的话,了解你的数据。@MitchelPaulin你能给我推荐你知道的任何模块吗?@PaulHodges哦,好的。。还有别的选择吗?漂亮的汤?