本文介绍了在页面源中查找自定义textin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是初学者
请帮我创建一个应用程序,使用C#.NET阅读网页源代码并在页面中查找自定义文本源和创建文本文件。 />
谢谢。
---
C#2010或2013
我曾尝试过:
搜索很多问题。
Hi,I Am Beginner
Please help me to create an application that Read web page source code by using C#.NET And Find Custom text in the page Source And Create a text file.
Thanks.
---
C# 2010 or 2013
What I have tried:
very much search on many questions.
推荐答案
using System;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string url = "http://www.codeproject.com/Questions/1121032/Find-custom-textin-pagesource";
WebBrowser web = new WebBrowser();
web.Url = new Uri(url);
web.DocumentCompleted += web_DocumentCompleted;
}
void web_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
WebBrowser web = (sender as WebBrowser);
string name = web.Document.GetElementById("ctl00_ctl00_MC_AMC_QuestionAuthorRepInfo_MemberName").InnerText;
MessageBox.Show(name);
string path = @"D\yourFile.txt";
if (!File.Exists(path))
using (StreamWriter sw = File.CreateText(path))
sw.WriteLine(name);
}
}
}
这篇关于在页面源中查找自定义textin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!