【发布时间】:2012-06-27 18:26:47
【问题描述】:
我有一个 HTML 页面,其中包含一些我想从网络服务器下载的文件名。 我需要阅读这些文件名以创建一个列表,该列表将传递给从服务器下载文件的 Web 应用程序。这些文件名有一些扩展名。
我已经深入研究过这个话题,但除了 -
- 正则表达式不能用于解析 HTML。
- 使用HTML Agility Pack
没有其他方法可以让我从 HTML 文件中搜索具有类似 filename.ext 模式的文本吗?
包含文件名的示例 HTML -
<p class=3DMsoNormal style=3D'margin-top:0in;margin-right:0in;margin-bottom=:0in; margin-left:1.5in;margin-bottom:.0001pt;text-indent:-.25in;line-height:normal;mso-list:l1 level3 lfo8;tab-stops:list 1.5in'><![if !supportLists]> <span style=3D'font-family:"Times New Roman","serif";mso-fareast-font-family:"Times New Roman"'><span style=3D'mso-list:Ignore'>1.<span style=3D'font:7.0pt "Times New Roman"'>
</span></span></span><![endif]><span style=3D'font-family:"Times New Roman","serif"; mso-fareast-font-family:"Times New Roman"'>**13572_PostAccountingReport_2009-06-03.acc**<o:p></o:p></span></p>
我不能使用HTML Agility Pack,因为我不允许下载和使用任何应用程序或工具。
这不能通过其他任何逻辑来实现吗?
这是我到目前为止所做的
string pageSource = "";
string geturl = @"C:\Documents and Settings\NASD_Download.mht";
WebRequest getRequest = WebRequest.Create(geturl);
WebResponse getResponse = getRequest.GetResponse();
using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
{
pageSource = sr.ReadToEnd();
pageSource.Replace("=", "");
}
var fileNames = from Match m in Regex.Matches(pageSource, @"[0-9]+_+[A-Za-z]+_+[0-9]+-+[0-9]+-+[0-9]+.+[a-z]")
select m.Value;
foreach (var s in fileNames)
Response.Write(s);
由于每个文件名中出现一些“=”,我无法获取文件名。如何删除pageSource string中出现的“=”
提前致谢
阿基尔
【问题讨论】:
-
我在示例中看不到文件名... :(
-
13572_PostAccountingReport_2009-06-03.acc
-
.ext在哪里?!它可以是每个扩展?规则是什么? -
.ext 只是一个例子。我的意思是它可以是任何 abc.acc 或 abc.zip 等。
-
所以这是不可能的,祝你今天愉快,我只是浪费时间写一个答案。 :(
标签: c# asp.net html regex html-agility-pack