本文介绍了从网站解析和编辑HTML的快速方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private String webText;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
WebClient web = new WebClient();
System.IO.Stream stream = web.OpenRead("https://de.wikipedia.org");
using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
{
webText = reader.ReadToEnd();
}
stream.Close();
richTextBox1.Text = webText;
}
}
}
我尝试了什么:
此代码可以很好地显示整个源代码。
但是我想去使用getElementById函数通过源代码。
显然这个函数仅限于htmlDocument类型,我无法找到一种方法将我从流中返回的字符串转换为htmlDocument。
有没有办法从字符串转换成htmlDocument?
或者不是将源代码写入字符串,我可以在第一时间创建一个htmlDocument吗?
谢谢
What I have tried:
This Code is working quite well to display the whole sourcecode.
But i would like to go through the sourcecode using the getElementById function.
Apparently this function is limited to htmlDocument types and i couldnt find a way to convert the string i get back from my stream into a htmlDocument.
Is there a way to convert into htmlDocument from string?
Or instead of writing the sourcecode into a string, can i create a htmlDocument in the first place?
Thanks
推荐答案
这篇关于从网站解析和编辑HTML的快速方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!