高分求助!读取网页内容的!

headsonlkc 2011-04-12 09:10:05
网页有查询功能的
如何通过WINFROM实现查询功能
并得查询结果


就好象在软件上,实现百度的查询,并取得结果!

给个例子,再加点分都愿意!

先说声谢谢!
...全文
124 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
cjh200102 2011-04-13
  • 打赏
  • 举报
回复
楼上都不错
kingdom_0 2011-04-13
  • 打赏
  • 举报
回复
html页面的编码要和你的配置一致。获取的时候,也要用同样的方式来获取
<globalization fileEncoding="gb2312" requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN"/>
  • 打赏
  • 举报
回复
你可以在页面标头加一句:ResponseEncoding="UTF-8"看是否可以

如果不行,你在web.config当中配置一下

<globalization fileEncoding="gb2312" requestEncoding="gb2312" responseEncoding="gb2312" culture="zh-CN"/>
headsonlkc 2011-04-13
  • 打赏
  • 举报
回复
现在已经可以读取数据,但汉字乱码了
  • 打赏
  • 举报
回复
机器人 2011-04-12
  • 打赏
  • 举报
回复
你下个 Fiddler2 ,然后在页面上操作一次查询。把RAW Request 拷贝出来参考模拟。
lunasea0_0 2011-04-12
  • 打赏
  • 举报
回复
用webbroswer打开网页,最简单了。更常用的是让网页提供一个WebService。如果非要一个Post请求也可以,用HttpWebRequest模拟一个Post请求。
headsonlkc 2011-04-12
  • 打赏
  • 举报
回复
这个是我的读取网页部分,只读取数据可以,但如果要求有查询功能呢?
public string Gethtml(string url)
{
string tmpurl = UrlEncode(url);
try
{
HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(tmpurl);
loHttp.Timeout = 30000; // 10 secs
loHttp.UserAgent = "Mozilla/4.0";
HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse();
Encoding enc = System.Text.Encoding.GetEncoding("gb2312"); //gb2312中文编码
if (loWebResponse.ContentEncoding.Length > 0)
{
enc = Encoding.GetEncoding(loWebResponse.ContentEncoding);
}
StreamReader loResponseStream = new StreamReader(loWebResponse.GetResponseStream(), enc);
string tmphtml = loResponseStream.ReadToEnd();
loResponseStream.Close();
loWebResponse.Close();
return tmphtml;
}
catch (Exception er)
{
//TODO : 处理错误
return er.ToString();
}
}

提交查询好象要用到这个的httpWebRequest.Referer
但显示远程服务器反回。。。的什么的错误信息!
jhtchina 2011-04-12
  • 打赏
  • 举报
回复
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.cn");
WebResponse wr = request.GetResponse();
Stream s = wr.GetResponseStream();
StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("gb2312"));
string content = sr.ReadToEnd();
Response.Write(content);
sr.Close();
s.Close();
wr.Close();
段传涛 2011-04-12
  • 打赏
  • 举报
回复
我1年前的一个问题
参考
http://topic.csdn.net/u/20100107/11/23002f50-f11a-41ed-9af9-1d0a04aacc3c.html
段传涛 2011-04-12
  • 打赏
  • 举报
回复
private void button2_Click(object sender, EventArgs e)
{
object Zero = 0;
object EmptyString = "";
axWebBrowser1.Navigate(textBox1.Text, ref Zero, ref EmptyString, ref EmptyString, ref EmptyString);
}

private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
IHTMLDocument2 HTMLDocument = (IHTMLDocument2)axWebBrowser1.Document;
IHTMLElementCollection links = HTMLDocument.links;

listBox1.Items.Clear();
string uspath = Application.StartupPath + "\\WriteLines.html";
uspath.Remove(0);
//using ( StreamWriter sw = new StreamWriter(@"C:\WriteLines.html", true))
using (StreamWriter sw = new StreamWriter(uspath, true))
foreach (HTMLAnchorElementClass el in links)
{
listBox1.Items.Add(el.outerHTML);
sw.WriteLine(el.outerHTML);
sw.Close();
}
}
Peter200694013 2011-04-12
  • 打赏
  • 举报
回复
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.baidu.cn");
WebResponse wr = request.GetResponse();
Stream s = wr.GetResponseStream();
StreamReader sr = new StreamReader(s, System.Text.Encoding.GetEncoding("gb2312"));
string content = sr.ReadToEnd();
Response.Write(content);
sr.Close();
s.Close();
wr.Close();
暖枫无敌 2011-04-12
  • 打赏
  • 举报
回复
神马意思?是实现搜索引擎的效果?
是的话,在.NET下可以考虑使用Luncene.net实现

110,567

社区成员

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

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

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