Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
C#
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?
Posted
Updated 7-Oct-14 2:15am
v2
Comments
[no name] 7-Oct-14 8:22am    
you need all the website text or specific text ?
Fail4FunTV 7-Oct-14 8:27am    
specific text from id "quick-details"
Kornfeld Eliyahu Peter 7-Oct-14 8:35am    
What does it mean 'doesn't work'?
How did you loaded the page?
Are you aware that 'quick-details' is a <dl> element and has no value attribute?

1 solution

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;
}
 
Share this answer
 
Comments
Fail4FunTV 7-Oct-14 8:58am    
I attached it like this:

private void button3_Click(object sender, EventArgs e)
{
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;
}
}

But where am i supposed to see the text?
[no name] 7-Oct-14 9:05am    
replace string cell = m.Groups[1].Value; by string cell = m.Groups[0].Value;
and change
MatchCollection m1 = Regex.Matches(get, @"(<dl class=""dl-horizontal"" id=""quick-details"">)(.*?)(</dl>)", RegexOptions.Singleline);
to
MatchCollection m1 = Regex.Matches(get, @"(quick-details)(.*?)(</dl>)", RegexOptions.Singleline);
then in the string cell you will have the text between quick-details and </dl>
Fail4FunTV 7-Oct-14 9:10am    
And to get the text i want into a textbox i do:

textBox7.Text = m1.ToString(); ?
[no name] 7-Oct-14 9:11am    
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, @"(quick-details)(.*?)(</dl>)", RegexOptions.Singleline);
foreach (Match m in m1)
{
string cell = m.Groups[0].Value;
}
textBox7.Text = cell;
[no name] 7-Oct-14 9:12am    
string cell="";
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, @"(quick-details)(.*?)(</dl>)", RegexOptions.Singleline);
foreach (Match m in m1)
{
cell = m.Groups[0].Value;
}
textBox7.Text = cell;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900