在页面源中查找自定义textin [英] Find custom textin pagesource
本文介绍了在页面源中查找自定义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.
推荐答案
这个可以通过多种方式完成,这是其中之一
创建一个Windows应用程序并添加 webbrowser [ ^ ]控制它。
加载网址并从DOM中查询元素以读取文本和将其写入文本文件 [ ^ ]
简单示例:它会将您的名称保存到文本文件中,方法是将此问题URL传递给它。
This can be done in many ways, this is one of them
Create a windows application and add webbrowser[^] control to it.
Load the url and query the element from the DOM to read the text and write it into a text file[^]
Simple example: it will save your name to the text file, by passing this question url to it.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文