使用 FINDSTR 的这个 BAT 文件有什么问题?
我需要输入一系列链接,这些链接会转到类似格式的页面,但内容和一个标签有所不同。
编辑
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的方法存在几个问题。首先,FINDSTR 无法在远程 URL 中找到。所以你需要下载它们。
从以下代码开始,该代码使用
CURL
进行下载,以帮助您入门。编辑:
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.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