获取网页源代码并检索其控件. [英] Fetching a Web page source code and retriving its controls.
问题描述
Hello程序员,
这是我在代码项目站点上的第一个问题,我希望能得到一个答案-我最好的程序员朋友向我推荐了这个站点,因为我是最好的-并且我正在寻找解决方案;
我需要从外部网页获取选定的数据...
我已经尝试通过获取所需的页面源代码进行尝试,并且可以通过以下代码来做到这一点:
Hello Programmers,
this is my first question at code project site and I wish I could get an answer - my best programmer friend suggested this site to me as the best - and I''m searching for a solution for;
I need to get selected data from an external web page...
I''ve tried by fetching the desired page source code and I could do that by the following code:
...
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
...
private void BtnGetSc_Click(object sender, EventArgs e)
{
string url = TbUrl.Text;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
RtbSC.Text = sr.ReadToEnd();
sr.Close();
}
...
但是我被困在将源代码转换为C#控件的过程中,所以有什么建议吗?!
提示:用直言不讳;我需要读取任何网页并从中获取文本框值.
预先感谢您的答复:)
but I''m stuck in converting this source code to a C# controls, so any suggestion??!
Hint: in outher words; I need to read any web page and fetch a text box value from it.
thanks in advance for any reply :)
推荐答案
欢迎来到Code Project,您的朋友显然是非常明智的. :)
您不能从页面内容创建C#控件,因为它是该控件的呈现HTML输出.如何创建它可以有多种方式.
如果需要控件的值,则可以使用正则表达式来解析页面元素,或使用类似 ^ ]
Welcome to Code Project, your friend is obviously very wise. :)
You can''t create a C# control from the page contents since is the rendered HTML output of that control. How it is created could be any number of ways.
If you want the value of a control you can use a Regular Expression to parse the page elements or use something like this Parsing HTML Tags in C#[^]
谢谢,这是一篇很棒的文章,但我发现youtube视频对我有很大帮助,我只想分享它:
创建Web抓取器第1部分-C#C Sharp Visual Studio 2008"
Thanks Mark it is really great article but I\ve found a youtube video helps me so much and I''m just want to share it:
"Creating a Web Scraper Part 1 - C# C Sharp Visual Studio 2008"
这篇关于获取网页源代码并检索其控件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!