使用 FINDSTR 的这个 BAT 文件有什么问题?

发布于 2024-12-11 04:03:27 字数 774 浏览 1 评论 0原文

我需要输入一系列链接,这些链接会转到类似格式的页面,但内容和一个标签有所不同。

编辑

input.txt
/category/apples-and-oranges.html
/category/pineapples.html
/category/asparagus.html
/category/brussel-sprouts.html
/category/passion-fruit.html

假设涉及水果的页面有

Fruit!

而非水果页面没有,但它们属于一个类别。该程序将检查 http://www.mysite.com 的这些扩展名,然后创建一个新列表:

output.txt
/category/apples-and-oranges.html
/category/pineapples.html
/category/passion-fruit.html

这是我到目前为止所得到的

for /f %%A in (input.txt) DO (
    for "tokens=1,2 delims=:" %%b in ('FINDSTR [/R] [/I] [/S] [/C:"<H1>.*Fruit!.*</H1>"] [[http://]www.mysite.com/%%A[*.html]]') DO (
    echo ^<%%A> > <output.txt>
)

:)

I need to take input of a list of links that go to pages of similar format, with the difference of content and one tag.

EDIT

input.txt
/category/apples-and-oranges.html
/category/pineapples.html
/category/asparagus.html
/category/brussel-sprouts.html
/category/passion-fruit.html

Assume that the pages involving fruit have <h1>Fruit!</h1> while the non-fruit pages don't, but they're under one category. The program would check those extensions to http://www.mysite.com and then create a new list:

output.txt
/category/apples-and-oranges.html
/category/pineapples.html
/category/passion-fruit.html

Here's what I've got so far:

for /f %%A in (input.txt) DO (
    for "tokens=1,2 delims=:" %%b in ('FINDSTR [/R] [/I] [/S] [/C:"<H1>.*Fruit!.*</H1>"] [[http://]www.mysite.com/%%A[*.html]]') DO (
    echo ^<%%A> > <output.txt>
)

)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卷耳 2024-12-18 04:03:27

您的方法存在几个问题。首先,FINDSTR 无法在远程 URL 中找到。所以你需要下载它们。

从以下代码开始,该代码使用 CURL 进行下载,以帮助您入门。

@echo off
FOR /F %%A in (input.txt) DO (
  curl --output temp.html http:www.mysite.com/%%A 
  FOR /F "tokens=1,2 delims=:" %%B in ('FINDSTR /I /R "<H1>.*Fruit.*</H1>" temp.html') DO (
    ECHO %%A
  )
)

编辑:

cURL 不是 Windows 命令,而是外部实用程序。 http://en.wikipedia.org/wiki/CURL 。您需要安装它。还有另一个众所周知的网络下载工具,GNU Wget http://en .wikipedia.org/wiki/Wget。有关更多选项,请参阅 Superuser.com 上的此问题 https://superuser.com/questions /299754/wget-curl-alternative-native-to-windows

There are several problems in your approach. First of all FINDSTR cannot find in remote URLs. So you need to download them.

Begin with the following code, that uses CURL for downloading, to get you started.

@echo off
FOR /F %%A in (input.txt) DO (
  curl --output temp.html http:www.mysite.com/%%A 
  FOR /F "tokens=1,2 delims=:" %%B in ('FINDSTR /I /R "<H1>.*Fruit.*</H1>" temp.html') DO (
    ECHO %%A
  )
)

Edit:

cURL is not a Windows command, it's an external utility. http://en.wikipedia.org/wiki/CURL . You'll need to install it. There is another well know tool for web download, GNU Wget http://en.wikipedia.org/wiki/Wget . For more options, see this question on Superuser.com https://superuser.com/questions/299754/wget-curl-alternative-native-to-windows

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文