获取列表的最快方法 来自本地主机网站上所有页面的值

发布于 2024-07-09 02:54:09 字数 354 浏览 4 评论 0原文

我本质上是想抓取我的本地站点并创建所有标题和 URL 的列表,如下所示:

http://localhost/mySite/Default.aspx      My Home Page
http://localhost/mySite/Preferences.aspx  My Preferences
http://localhost/mySite/Messages.aspx     Messages

我正在运行 Windows。 我对任何有用的东西都持开放态度——C# 控制台应用程序、PowerShell、一些现有工具等。我们可以假设该标签确实存在于文档中。

注意:我需要实际抓取文件,因为标题可能是在代码而不是标记中设置的。

I essentially want to spider my local site and create a list of all the titles and URLs as in:

http://localhost/mySite/Default.aspx      My Home Page
http://localhost/mySite/Preferences.aspx  My Preferences
http://localhost/mySite/Messages.aspx     Messages

I'm running Windows. I'm open to anything that works--a C# console app, PowerShell, some existing tool, etc. We can assume that the tag does exist in the document.

Note: I need to actually spider the files since the title may be set in code rather than markup.

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

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

发布评论

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

评论(5

差↓一点笑了 2024-07-16 02:54:09

一个快速而肮脏的 Cygwin Bash 脚本可以完成这项工作:

#!/bin/bash
for file in $(find $WWWROOT -iname \*.aspx); do
  echo -en $file '\t'
  cat $file | tr '\n' ' ' | sed -i 's/.*<title>\([^<]*\)<\/title>.*/\1/'
done

说明:这会找到根目录 $WWWROOT 下的每个 .aspx 文件,用空格替换所有换行符,以便 </code> 之间没有换行符> 和 <code>,然后抓取这些标签之间的文本。

A quick and dirty Cygwin Bash script which does the job:

#!/bin/bash
for file in $(find $WWWROOT -iname \*.aspx); do
  echo -en $file '\t'
  cat $file | tr '\n' ' ' | sed -i 's/.*<title>\([^<]*\)<\/title>.*/\1/'
done

Explanation: this finds every .aspx file under the root directory $WWWROOT, replaces all newlines with spaces so that there are no newlines between the <title> and </title>, and then grabs out the text between those tags.

会发光的星星闪亮亮i 2024-07-16 02:54:09

我认为类似于 Adam Rosenfield 建议的 就是您想要的,但如果您想要实际的 URL,请尝试使用 wget。 通过一些适当的选项,它将打印出您网站上所有页面的列表(并下载它们,也许您可​​以使用 --spider 抑制)。 wget 程序可通过普通的 Cygwin 安装程序获得。

I think a script similar to what Adam Rosenfield suggested is what you want, but if you want the actual URLs, try using wget. With some appropriate options, it will print out a list of all the pages on your site (plus download them, which maybe you can suppress with --spider). The wget program is avaliable through the normal Cygwin installer.

反目相谮 2024-07-16 02:54:09

好的,我对 Windows 不熟悉,但为了让您找到正确的方向:使用带有

的 XSLT 转换
在那里取回标题,或者如果可以的话,使用 XPath '/head/title' 取回标题。

Ok, I'm not familiar with Windows, but to get you in the right direction: use a XSLT transformation with

<xsl:value-of select="/head/title" />
in there to get the title back or if you can, use the XPath '/head/title' to get the title back.

如梦 2024-07-16 02:54:09

我会使用上面详细介绍的 wget 。
确保您的网站上没有任何蜘蛛陷阱

I would use wget as detailed above.
Be sure you don't have any spider traps on your site.

萧瑟寒风 2024-07-16 02:54:09

你应该考虑使用 scrapy shell

查看

http://doc.scrapy.org/intro/tutorial。 在控制台中的html

中放置如下内容:

hxs.x('/html/head/title/text()').extract()

如果你想要所有标题,你应该做一个蜘蛛......这真的很容易。

还可以考虑迁移到 Linux :P

you should consider using scrapy shell

check out

http://doc.scrapy.org/intro/tutorial.html

in console put something like this :

hxs.x('/html/head/title/text()').extract()

if you want all titles, you should do a spider...it really easy.

Also consider to move to linux :P

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