[C#]如何从网站上获取文本到表格中 [英] [C#]How Do I Get Text From Website Into The Form
本文介绍了[C#]如何从网站上获取文本到表格中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从网站上获取文本框或主页上的文字?
这是网站:http://www.macvendorlookup.com/ [ ^ ]
这是我的信息:
div class = col-md-6
idquick-details
我试过这样:
< pre lang =c#> web.Document.GetElementById( quick-details)。GetAttribute( Value,textBox7.Text);
但这不起作用,文本框文本只是空白..我做错了什么?
解决方案
试试这个:
System.IO.StreamReader阅读器;
WebRequest request = WebRequest.Create(http://www.macvendorlookup.com/);
request.Timeout = 120000;
WebResponse response = request.GetResponse();
reader = new System.IO.StreamReader(response.GetResponseStream());
string get = reader.ReadToEnd();
MatchCollection m1 = Regex.Matches(get,@(< dl class =dl-horizontalid =quick-details>)(。*?)(< / dl>), RegexOptions.Singleline);
foreach(匹配m in m1)
{
string cell = m.Groups [1] .Value;
}
How can i get a text from website to a textbox or something on my main form?
This is the website: http://www.macvendorlookup.com/[^]
This is info i have:
div class="col-md-6"
id"quick-details"
I tried like this:
web.Document.GetElementById("quick-details").GetAttribute("Value", textBox7.Text);
But that doesn't work, the textbox text is just blank.. What am i doing wrong?
解决方案
try this :
System.IO.StreamReader reader; WebRequest request = WebRequest.Create("http://www.macvendorlookup.com/"); request.Timeout = 120000; WebResponse response = request.GetResponse(); reader = new System.IO.StreamReader(response.GetResponseStream()); string get = reader.ReadToEnd(); MatchCollection m1 = Regex.Matches(get, @"(<dl class="dl-horizontal" id="quick-details">)(.*?)(</dl>)", RegexOptions.Singleline); foreach (Match m in m1) { string cell = m.Groups[1].Value; }
这篇关于[C#]如何从网站上获取文本到表格中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文