从别的网页上抓取部分内容 实现我自己的功能

mrslikelin 2012-08-21 02:57:54
我想从另一个网站中抓取新闻列表到我的网站中,我现在能得到目标源代码,并在TEXTBOX文本中显示,怎么处理这段内容只保留我想要的HTML片段内容?


也就是说我想再别的网页上抓取 人民币汇率那么一部分内容 放在我自己的网页上 ,现在整个网页是抓出来了 我想的是怎么去抓 我想要的那一部分内容
...全文
168 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
huayy 2012-08-27
  • 打赏
  • 举报
回复
如果不知道正则,也可以通过两个指定的字符,取字符中的中间值。

Function GetKey(ByVal HTML, ByVal Start, ByVal Last)
Dim body1 = Split(HTML, Start)
Dim body2 = Split(body1(1), Last)
GetKey = body2(0)
End Function
qvbzyx 2012-08-27
  • 打赏
  • 举报
回复
using System;
using System.Net;
using System.Text;
using System.IO;


public class Test
{
// Specify the URL to receive the request.
public static void Main (string[] args)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create (args[0]);

// Set some reasonable limits on resources used by this request
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
// Set credentials to use for this request.
request.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response = (HttpWebResponse)request.GetResponse ();

Console.WriteLine ("Content length is {0}", response.ContentLength);
Console.WriteLine ("Content type is {0}", response.ContentType);

// Get the stream associated with the response.
Stream receiveStream = response.GetResponseStream ();

// Pipes the stream to a higher level stream reader with the required encoding format.
StreamReader readStream = new StreamReader (receiveStream, Encoding.UTF8);

Console.WriteLine ("Response stream received.");
Console.WriteLine (readStream.ReadToEnd ());
response.Close ();
readStream.Close ();
}
}

/*
The output from this example will vary depending on the value passed into Main
but will be similar to the following:

Content length is 1542
Content type is text/html; charset=utf-8
Response stream received.
<html>
...
</html>

*/


是你_不懂 2012-08-24
  • 打赏
  • 举报
回复
lz,希望问题解决后共享一下,我也需要这个功能。
xieyonjie 2012-08-24
  • 打赏
  • 举报
回复
自己一点想法都没有...要怎么用~!?
mrslikelin 2012-08-24
  • 打赏
  • 举报
回复
真不知道呢 你们有列子吗 可以发一个给我吗

还有 资源文件怎么取出值来 我邮箱919290241@qq.com
  • 打赏
  • 举报
回复
你应该说你抓的是什么数据,然后你想得到什么,贴内容

一般都是正则 或者 利用webbroswer来分析HTMLDocument
wangxuebo 2012-08-21
  • 打赏
  • 举报
回复
正则表达式来匹配截取

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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