******100分,求c# 保存网页的方法********

zwj1234 2005-11-22 12:48:21
我现在用WebClient能保存主页面,但图存不下来
我希望能用c#实现类似ie的网页保存的方法
保存后图片什么的都要有。
高手帮忙啊
...全文
170 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwj1234 2005-11-22
  • 打赏
  • 举报
回复
可有些图是相对路径的,要怎么弄呢?
Qqwwee_Com 2005-11-22
  • 打赏
  • 举报
回复
其实你已经走了第一步,
你把html保存下来以后,从中间提取出连接,图片的地址,继续down下来。。

#region 广告开始

CSDN小助手 V2.5,更快、更爽、更方便的浏览CSDN论坛!
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2

#endregion
JzeroBiao 2005-11-22
  • 打赏
  • 举报
回复
学习。。。上面有2种方法,边种快?
arice1983 2005-11-22
  • 打赏
  • 举报
回复
查找到图的路径的代码,把相对的换成绝对的吧,具体怎样,不会……
Qqwwee_Com 2005-11-22
  • 打赏
  • 举报
回复
相对和绝对路径都是判断的
一般http://是绝对路径,其他都是相对路径
System.Uri很容易处理这样的路径的。

#region 广告开始

CSDN小助手 V2.5,更快、更爽、更方便的浏览CSDN论坛!
界面:http://blog.csdn.net/Qqwwee_Com/archive/2005/11/05/523395.aspx
下载:http://szlawbook.com/csdnv2

***
我们每回答一个问题,
就谋杀了提问者一个思考的机会,
而这个思考的机会可能让他获得10倍的知识,
所以,我们不下地狱谁下地狱?
***

#endregion
jinjazz 2005-11-22
  • 打赏
  • 举报
回复
图片都在你的ie缓存里面,找到缓存文件copy过来就可以了
//using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
public struct INTERNET_CACHE_ENTRY_INFO
{
public int dwStructSize;
public IntPtr lpszSourceUrlName;
public IntPtr lpszLocalFileName;
public int CacheEntryType;
public int dwUseCount;
public int dwHitRate;
public int dwSizeLow;
public int dwSizeHigh;
public FILETIME LastModifiedTime;
public FILETIME ExpireTime;
public FILETIME LastAccessTime;
public FILETIME LastSyncTime;
public IntPtr lpHeaderInfo;
public int dwHeaderInfoSize;
public IntPtr lpszFileExtension;
public int dwExemptDelta;
}
[DllImport("wininet.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern IntPtr FindFirstUrlCacheEntry([MarshalAs(UnmanagedType.LPTStr)] string UrlSearchPattern, IntPtr lpFirstCacheEntryInfo, ref int lpdwFirstCacheEntryInfoBufferSize);
[DllImport("wininet.dll", SetLastError=true, CharSet=CharSet.Auto)]
public static extern bool GetUrlCacheEntryInfo( [MarshalAs(UnmanagedType.LPTStr)] string lpszUrlName, IntPtr lpCacheEntryInfo, ref int lpdwCacheEntryInfoBufferSize );
public static string GetCatchFileName(string url)
{
int nNeeded = 0, nBufSize;
IntPtr buf;
FindFirstUrlCacheEntry( null, IntPtr.Zero, ref nNeeded );
nBufSize = nNeeded; buf = Marshal.AllocHGlobal( nBufSize );
GetUrlCacheEntryInfo(url,buf,ref nNeeded);
INTERNET_CACHE_ENTRY_INFO CacheItem;
GetUrlCacheEntryInfo(url,buf,ref nNeeded);
CacheItem = (INTERNET_CACHE_ENTRY_INFO) Marshal.PtrToStructure( buf,typeof(INTERNET_CACHE_ENTRY_INFO) );
string res=Marshal.PtrToStringAuto(CacheItem.lpszLocalFileName);
return(res);
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧