C# 使用webbrowser解析html网站中的文本?

C# 使用webbrowser解析html网站中的文本?,c#,webbrowser-control,C#,Webbrowser Control,我想创建一个访问票证管理系统网站的表单,以便在windows表单应用程序中,在一些文本框中,显示创建人:、票证标题、创建地点等信息。 我尝试将过滤器设置为从某一行开始: var ticketLines = codes.Where(m => m.StartsWith("<TD style=\"WIDTH: 65px; HEIGHT: 22px; LEFT: 110px\" class=hb-table-cell>")); 为此,我创建了一个列表,在其中我将发布我需要的某些信息:

我想创建一个访问票证管理系统网站的表单,以便在windows表单应用程序中,在一些文本框中,显示创建人:、票证标题、创建地点等信息。 我尝试将过滤器设置为从某一行开始:

var ticketLines = codes.Where(m => m.StartsWith("<TD style=\"WIDTH: 65px; HEIGHT: 22px; LEFT: 110px\" class=hb-table-cell>"));
为此,我创建了一个列表,在其中我将发布我需要的某些信息:

List<string> ticketTitles = new List<string>();
            foreach (string line in ticketLines)
            {   
                //select the line from which you want to start scrapping
                int y = codes.IndexOf(line);
                //ticket title
                ticketTitles.Add(codes[y + 1].Substring(codes[y + 1].IndexOf(">") + 1, codes[y + 1].Length - codes[y + 1].IndexOf(">") - 6));
                //created at
                ticketTitles.Add(codes[y+2].Substring(codes[y+2].IndexOf(">")+1, codes[y+2].Length - codes[y+2].IndexOf(">") - 6 )); 
            }
在我的表单中,我有一个“登录”按钮和一个“生成”按钮。“生成”按钮通过输入特定票据id激活页面

到目前为止,我的进展是创建了自动登录按钮,没有这个按钮,您无法以特定票号进入网站

如何在文本框中显示我的元素?有人能给我解释一下这个过程吗? 有人试图帮助我并将此表单中的所有代码保存到txt中:

<DIV style="WIDTH: 416px; HEIGHT: 134px" class=hb-ui-grid>
<DIV style="WIDTH: 416px; HEIGHT: 23px" class=hb-ui-grid-header-outbox>
<DIV style="WIDTH: 19px; HEIGHT: 23px" class="goog-inline-block hb-ui-grid-header-check"><SPAN aria-checked=false class="goog-checkbox goog-checkbox-unchecked" title="Select all tickets" role=checkbox tabIndex=0 yH="checkbox" unselectable="on" closure_uid_7r0z52="58"></SPAN></DIV>
<DIV hideFocus style="WIDTH: 376px; HEIGHT: 23px" class="hb-ui-grid-header hb-ui-grid-header-horizontal goog-inline-block" tabIndex=0 unselectable="on" closure_uid_7r0z52="56">
<TABLE style="WIDTH: 2095px" class=hb-ui-grid-header-content unselectable="on" aH="0">
<TBODY unselectable="on">
<TR unselectable="on"><TD style="TEXT-ALIGN: center; WIDTH: 25px; HEIGHT: 23px" id=:1i class=hb-ui-grid-column title=History unselectable="on" model="H">H</TD><TD style="TEXT-ALIGN: center; WIDTH: 25px; HEIGHT: 23px" id=:1j class=hb-ui-grid-column title=Attachments unselectable="on" model="A">A</TD><TD style="TEXT-ALIGN: center; WIDTH: 60px; HEIGHT: 23px" id=:1k class=hb-ui-grid-column title=Clone unselectable="on" model="C">C</TD><TD style="WIDTH: 65px; HEIGHT: 23px" id=:1l class=hb-ui-grid-column title="Ticket ID" unselectable="on" model="1">Ticket ID</TD><TD style="WIDTH: 542px; HEIGHT: 23px" id=:1m class=hb-ui-grid-column title=Title unselectable="on" model="109">Title</TD><TD style="WIDTH: 95px; HEIGHT: 23px" id=:1n class=hb-ui-grid-column title="Reported on" unselectable="on" model="115">Reported on</TD><TD style="WIDTH: 84px; HEIGHT: 23px" id=:1o class=hb-ui-grid-column title="Detected on" unselectable="on" model="118">Detected on</TD><TD style="WIDTH: 132px; HEIGHT: 23px" id=:1p class=hb-ui-grid-column title="Detected by" unselectable="on" model="119">Detected by</TD><TD style="WIDTH: 118px; HEIGHT: 23px" id=:1q class=hb-ui-grid-column title="System SW-Rev." unselectable="on" model="129">System SW-Rev.</TD><TD style="WIDTH: 126px; HEIGHT: 23px" id=:1r class=hb-ui-grid-column title="Integrated in version" unselectable="on" model="404">Integrated in version</TD><TD style="WIDTH: 16px; HEIGHT: 23px" id=:1s class=hb-ui-grid-column title="Tested in version" unselectable="on" model="507">Tested in version</TD><TD style="WIDTH: 31px; HEIGHT: 23px" id=:1t class=hb-ui-grid-column title=Result unselectable="on" model="504">Result</TD><TD style="WIDTH: 162px; HEIGHT: 23px" id=:1u class=hb-ui-grid-column title="Last change by user" unselectable="on" model="51">Last change by user</TD><TD style="WIDTH: 73px; HEIGHT: 23px" id=:1v class=hb-ui-grid-column title="Ticket state" unselectable="on" model="53">Ticket state</TD><TD style="WIDTH: 102px; HEIGHT: 23px" id=:1w class=hb-ui-grid-column title="Ticket owner" unselectable="on" model="76">Ticket owner</TD><TD style="WIDTH: 99px; HEIGHT: 23px" id=:1x class=hb-ui-grid-column title="Ticket step" unselectable="on" model="55"><SPAN class=hb-ui-grid-sort unselectable="on">▲</SPAN>Ticket step</TD><TD style="WIDTH: 86px; HEIGHT: 23px" id=:1y class=hb-ui-grid-column title="Last change date" unselectable="on" model="52">Last change date</TD><TD style="WIDTH: 64px; HEIGHT: 23px" id=:1z class=hb-ui-grid-column title=Priority unselectable="on" model="215">Priority</TD><TD style="WIDTH: 95px; HEIGHT: 23px" id=:20 class=hb-ui-grid-column title="Sequence of Activity" unselectable="on" model="68">Sequence of Activity</TD></TR></TBODY></TABLE></DIV>
<DIV aria-haspopup=true style="DISPLAY: none" class="goog-inline-block hb-grid-menu-button" title="Overview options" role=button aria-activedescendant="" yH="button" unselectable="on" closure_uid_7r0z52="60">
<DIV class="goog-inline-block hb-grid-menu-button-outer-box" unselectable="on">
<DIV class="goog-inline-block hb-grid-menu-button-inner-box" unselectable="on">
<DIV class="goog-inline-block hb-grid-menu-button-caption" unselectable="on"></DIV>
<DIV class="goog-inline-block hb-grid-menu-button-dropdown" unselectable="on">&nbsp;</DIV></DIV></DIV></DIV></DIV>
<DIV style="WIDTH: 416px; HEIGHT: 82px" class=hb-ui-grid-scrollarea unselectable="on" closure_uid_7r0z52="71">
<DIV style="WIDTH: 20px; HEIGHT: 64px" class=hb-ui-grid-pane unselectable="on">
<TABLE style="LINE-HEIGHT: 23px; BORDER-SPACING: 0; WIDTH: 0px; BORDER-COLLAPSE: separate; TABLE-LAYOUT: fixed; OVERFLOW: hidden; hasLayout: -1" cellSpacing=0>
<TBODY>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 15px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell><SPAN style="-webkit-user-select: none" class=hb-table-cell-check-box></SPAN></TD></TR>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 15px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell><SPAN style="-webkit-user-select: none" class=hb-table-cell-check-box></SPAN></TD></TR>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 15px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell><SPAN style="-webkit-user-select: none" class=hb-table-cell-check-box></SPAN></TD></TR></TBODY></TABLE></DIV>
<DIV style="WIDTH: 378px; HEIGHT: 64px" class=hb-ui-grid-pane unselectable="on" closure_uid_7r0z52="66">
<TABLE style="LINE-HEIGHT: 23px; BORDER-SPACING: 0; WIDTH: 0px; BORDER-COLLAPSE: separate; TABLE-LAYOUT: fixed; OVERFLOW: hidden; hasLayout: -1" cellSpacing=0>
<TBODY>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell>
<DIV class=hb-ui-calendar></DIV></TD>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 25px" class=hb-table-cell>
<DIV class=hb-ui-attachment></DIV></TD>
<TD style="WIDTH: 60px; HEIGHT: 22px; LEFT: 50px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 65px; HEIGHT: 22px; LEFT: 110px" class=hb-table-cell>1797443</TD>
<TD style="WIDTH: 542px; HEIGHT: 22px; LEFT: 175px" class=hb-table-cell>[MAP]Unexisting street through Ta Phuk river</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 717px" class=hb-table-cell>2016-01-19</TD>
<TD style="WIDTH: 84px; HEIGHT: 22px; LEFT: 812px" class=hb-table-cell>2016-01-19</TD>
<TD style="WIDTH: 132px; HEIGHT: 22px; LEFT: 896px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 118px; HEIGHT: 22px; LEFT: 1028px" class=hb-table-cell>152153.3.210</TD>
<TD style="WIDTH: 126px; HEIGHT: 22px; LEFT: 1146px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 16px; HEIGHT: 22px; LEFT: 1272px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 31px; HEIGHT: 22px; LEFT: 1288px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 162px; HEIGHT: 22px; LEFT: 1319px" class=hb-table-cell>IModoleev</TD>
<TD style="WIDTH: 73px; HEIGHT: 22px; LEFT: 1481px" class=hb-table-cell>Categorized</TD>
<TD style="WIDTH: 102px; HEIGHT: 22px; LEFT: 1554px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 99px; HEIGHT: 22px; LEFT: 1656px" class=hb-table-cell>Concluding</TD>
<TD style="WIDTH: 86px; HEIGHT: 22px; LEFT: 1755px" class=hb-table-cell>2016-01-26</TD>
<TD style="WIDTH: 64px; HEIGHT: 22px; LEFT: 1841px" class=hb-table-cell>C(3)</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 1905px" class=hb-table-cell>&nbsp;</TD></TR>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell>
<DIV class=hb-ui-calendar></DIV></TD>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 25px" class=hb-table-cell>
<DIV class=hb-ui-attachment></DIV></TD>
<TD style="WIDTH: 60px; HEIGHT: 22px; LEFT: 50px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 65px; HEIGHT: 22px; LEFT: 110px" class=hb-table-cell>1780104</TD>
<TD style="WIDTH: 542px; HEIGHT: 22px; LEFT: 175px" class=hb-table-cell>[DI]Preview map for country list is not refreshing</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 717px" class=hb-table-cell>2015-12-15</TD>
<TD style="WIDTH: 84px; HEIGHT: 22px; LEFT: 812px" class=hb-table-cell>2015-12-15</TD>
<TD style="WIDTH: 132px; HEIGHT: 22px; LEFT: 896px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 118px; HEIGHT: 22px; LEFT: 1028px" class=hb-table-cell>161153.3.210</TD>
<TD style="WIDTH: 126px; HEIGHT: 22px; LEFT: 1146px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 16px; HEIGHT: 22px; LEFT: 1272px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 31px; HEIGHT: 22px; LEFT: 1288px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 162px; HEIGHT: 22px; LEFT: 1319px" class=hb-table-cell>IModoleev</TD>
<TD style="WIDTH: 73px; HEIGHT: 22px; LEFT: 1481px" class=hb-table-cell>Categorized</TD>
<TD style="WIDTH: 102px; HEIGHT: 22px; LEFT: 1554px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 99px; HEIGHT: 22px; LEFT: 1656px" class=hb-table-cell>Concluding</TD>
<TD style="WIDTH: 86px; HEIGHT: 22px; LEFT: 1755px" class=hb-table-cell>2016-01-26</TD>
<TD style="WIDTH: 64px; HEIGHT: 22px; LEFT: 1841px" class=hb-table-cell>C(3)</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 1905px" class=hb-table-cell>&nbsp;</TD></TR>
<TR style="LINE-HEIGHT: 22px; WIDTH: 100%" class=hb-ui-grid-row>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 0px" class=hb-table-cell>
<DIV class=hb-ui-calendar></DIV></TD>
<TD style="WIDTH: 25px; HEIGHT: 22px; LEFT: 25px" class=hb-table-cell>
<DIV class=hb-ui-attachment></DIV></TD>
<TD style="WIDTH: 60px; HEIGHT: 22px; LEFT: 50px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 65px; HEIGHT: 22px; LEFT: 110px" class=hb-table-cell>1774770</TD>
<TD style="WIDTH: 542px; HEIGHT: 22px; LEFT: 175px" class=hb-table-cell>Only one street is shown for postcode 0010(Oslo)</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 717px" class=hb-table-cell>2015-12-08</TD>
<TD style="WIDTH: 84px; HEIGHT: 22px; LEFT: 812px" class=hb-table-cell>2015-12-08</TD>
<TD style="WIDTH: 132px; HEIGHT: 22px; LEFT: 896px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 118px; HEIGHT: 22px; LEFT: 1028px" class=hb-table-cell>101153.3.211</TD>
<TD style="WIDTH: 126px; HEIGHT: 22px; LEFT: 1146px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 16px; HEIGHT: 22px; LEFT: 1272px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 31px; HEIGHT: 22px; LEFT: 1288px" class=hb-table-cell>&nbsp;</TD>
<TD style="WIDTH: 162px; HEIGHT: 22px; LEFT: 1319px" class=hb-table-cell>IModoleev</TD>
<TD style="WIDTH: 73px; HEIGHT: 22px; LEFT: 1481px" class=hb-table-cell>Categorized</TD>
<TD style="WIDTH: 102px; HEIGHT: 22px; LEFT: 1554px" class=hb-table-cell>RBalan</TD>
<TD style="WIDTH: 99px; HEIGHT: 22px; LEFT: 1656px" class=hb-table-cell>Concluding</TD>
<TD style="WIDTH: 86px; HEIGHT: 22px; LEFT: 1755px" class=hb-table-cell>2016-01-26</TD>
<TD style="WIDTH: 64px; HEIGHT: 22px; LEFT: 1841px" class=hb-table-cell>C(3)</TD>
<TD style="WIDTH: 95px; HEIGHT: 22px; LEFT: 1905px" class=hb-table-cell>&nbsp;</TD></TR></TBODY></TABLE></DIV>
<DIV style="WIDTH: 18px; HEIGHT: 64px; TOP: 0px; LEFT: 398px" class=hb-grid-scroll-vertical unselectable="on" closure_uid_7r0z52="64">
<DIV style="WIDTH: 1px; HEIGHT: 92px; TOP: 0px; LEFT: 0px" unselectable="on"></DIV></DIV>
<DIV style="WIDTH: 378px; HEIGHT: 18px; TOP: 64px; LEFT: 20px" class=hb-grid-scroll-horizontal unselectable="on" closure_uid_7r0z52="65">
<DIV style="WIDTH: 2095px; HEIGHT: 1px; TOP: 0px; LEFT: 0px" unselectable="on"></DIV></DIV></DIV>
<DIV hideFocus class="goog-toolbar goog-toolbar-horizontal" role=toolbar yH="toolbar" unselectable="on" closure_uid_7r0z52="96">
<DIV id=:2d class="hb-toolbar-label goog-inline-block" tabIndex=0 unselectable="on" closure_uid_7r0z52="72">Mode:</DIV>
<DIV aria-haspopup=true id=:2i class="goog-inline-block goog-toolbar-menu-button" title="" role=button tabIndex=0 yH="button" unselectable="on" closure_uid_7r0z52="74">
<DIV class="goog-inline-block goog-toolbar-menu-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-menu-button-inner-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-menu-button-caption" unselectable="on">All</DIV>
<DIV class="goog-inline-block goog-toolbar-menu-button-dropdown" unselectable="on">&nbsp;</DIV></DIV></DIV></DIV>
<DIV style="DISPLAY: none" id=:2j class="goog-toolbar-separator goog-inline-block" role=separator yH="separator" unselectable="on">&nbsp;</DIV>
<DIV style="DISPLAY: none" id=:2k class="goog-inline-block goog-toolbar-button" title="First page" role=button yH="button" unselectable="on" closure_uid_7r0z52="77">
<DIV class="goog-inline-block goog-toolbar-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-button-inner-box" unselectable="on">
<DIV class="icon hb-grid-first" unselectable="on"></DIV></DIV></DIV></DIV>
<DIV style="DISPLAY: none" id=:2l class="goog-inline-block goog-toolbar-button" title="Previous page" role=button yH="button" unselectable="on" closure_uid_7r0z52="79">
<DIV class="goog-inline-block goog-toolbar-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-button-inner-box" unselectable="on">
<DIV class="icon hb-grid-left" unselectable="on"></DIV></DIV></DIV></DIV>
<DIV style="DISPLAY: none" id=:2m class="hb-toolbar-label goog-inline-block" unselectable="on" closure_uid_7r0z52="81">Page</DIV><INPUT style="DISPLAY: none" id=:2n class="hb-toolbar-editor goog-inline-block" value=1 maxLength=4 size=2 type=text closure_uid_7r0z52="83">
<DIV style="DISPLAY: none" id=:2o class="hb-toolbar-label goog-inline-block" unselectable="on" closure_uid_7r0z52="85">of 16</DIV>
<DIV style="DISPLAY: none" id=:2p class="goog-inline-block goog-toolbar-button" title="Next page" role=button yH="button" unselectable="on" closure_uid_7r0z52="87">
<DIV class="goog-inline-block goog-toolbar-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-button-inner-box" unselectable="on">
<DIV class="icon hb-grid-right" unselectable="on"></DIV></DIV></DIV></DIV>
<DIV style="DISPLAY: none" id=:2q class="goog-inline-block goog-toolbar-button" title="Last page" role=button yH="button" unselectable="on" closure_uid_7r0z52="89">
<DIV class="goog-inline-block goog-toolbar-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-button-inner-box" unselectable="on">
<DIV class="icon hb-grid-last" unselectable="on"></DIV></DIV></DIV></DIV>
<DIV id=:2r class="goog-toolbar-separator goog-inline-block" role=separator yH="separator" unselectable="on">&nbsp;</DIV>
<DIV id=:2s class="goog-inline-block goog-toolbar-button" title=Refresh role=button tabIndex=0 yH="button" unselectable="on" closure_uid_7r0z52="91">
<DIV class="goog-inline-block goog-toolbar-button-outer-box" unselectable="on">
<DIV class="goog-inline-block goog-toolbar-button-inner-box" unselectable="on">
<DIV class="icon icon hb-grid-refresh" unselectable="on"></DIV></DIV></DIV></DIV>
<DIV id=:2t class="goog-toolbar-separator goog-inline-block" role=separator yH="separator" unselectable="on">&nbsp;</DIV>
<DIV style="COLOR: black" id=:2u class="hb-toolbar-label goog-inline-block" tabIndex=0 unselectable="on" closure_uid_7r0z52="93">3 tickets found</DIV></DIV></DIV>
我的完整c代码如下:

using System.Threading;
namespace snippet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            this.webBrowser1.Navigate("https://elvis.harman.com/");

            while (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Thread.Sleep(100);
                Application.DoEvents();
            }

            //textBox1.Text= this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input").Count.ToString();


            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[0].InnerText = textBox1.Text;
            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[1].InnerText = textBox2.Text;
            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("button")[0].InvokeMember("click");

            //MessageBox.Show("Done!");


        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.webBrowser1.Navigate("https://elvis.harman.com/cgi-bin/ticket?TID=" + txtID.Text);
            Thread.Sleep(2000);
            //this.webBrowser1.Navigate("https://elvis.harman.com/cgi-bin/ticket?TID=" + txtID.Text);
            //Thread.Sleep(2000);

            this.webBrowser1.Update();
            //var b = this.webBrowser1.Document.GetElementById("ticketHeader").InnerHtml;

            // txtTitle.Text =  this.webBrowser1.Document.GetElementById("field_100");
            var codes = this.webBrowser1.Document.GetElementById("gridBox").InnerHtml.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(m => m.Trim()).ToList();

            //search in code for the line that starts with " "
            var ticketLines = codes.Where(m => m.StartsWith("<TD style=\"WIDTH: 65px; HEIGHT: 22px; LEFT: 110px\" class=hb-table-cell>"));

            //create list in which will store the text filtered
            List<string> ticketTitles = new List<string>();
            foreach (string line in ticketLines)
            {   
                //select the line from which you want to start scrapping
                int y = codes.IndexOf(line);
                //ticket title
                ticketTitles.Add(codes[y + 1].Substring(codes[y + 1].IndexOf(">") + 1, codes[y + 1].Length - codes[y + 1].IndexOf(">") - 6));
                //created at
                ticketTitles.Add(codes[y+2].Substring(codes[y+2].IndexOf(">")+1, codes[y+2].Length - codes[y+2].IndexOf(">") - 6 )); 
            }



            //int x = 1;

        }
我怎样才能复制这段代码呢。这似乎与在铬合金中使用检查元件不同?或者,我该如何在这方面做得更进一步


谢谢大家!

你的问题是什么?你的意思是你想生成一个新的表单,还是你已经有了一个表单,你只想提取一些InnerHtml值放在你已经创建的表单中?我不太清楚你在这里想要实现什么。您可以使用简单的WebApi来实现这一点,或者更难的方法是序列化和提取innerHtml。我不推荐。是的,我已经有了一个表单,但是当我尝试将过滤后的信息传递到texbox时,它不会显示任何内容
using System.Threading;
namespace snippet
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            this.webBrowser1.Navigate("https://elvis.harman.com/");

            while (this.webBrowser1.ReadyState != WebBrowserReadyState.Complete)
            {
                Thread.Sleep(100);
                Application.DoEvents();
            }

            //textBox1.Text= this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input").Count.ToString();


            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[0].InnerText = textBox1.Text;
            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("input")[1].InnerText = textBox2.Text;
            this.webBrowser1.Document.Window.Frames[2].Document.GetElementsByTagName("button")[0].InvokeMember("click");

            //MessageBox.Show("Done!");


        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.webBrowser1.Navigate("https://elvis.harman.com/cgi-bin/ticket?TID=" + txtID.Text);
            Thread.Sleep(2000);
            //this.webBrowser1.Navigate("https://elvis.harman.com/cgi-bin/ticket?TID=" + txtID.Text);
            //Thread.Sleep(2000);

            this.webBrowser1.Update();
            //var b = this.webBrowser1.Document.GetElementById("ticketHeader").InnerHtml;

            // txtTitle.Text =  this.webBrowser1.Document.GetElementById("field_100");
            var codes = this.webBrowser1.Document.GetElementById("gridBox").InnerHtml.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(m => m.Trim()).ToList();

            //search in code for the line that starts with " "
            var ticketLines = codes.Where(m => m.StartsWith("<TD style=\"WIDTH: 65px; HEIGHT: 22px; LEFT: 110px\" class=hb-table-cell>"));

            //create list in which will store the text filtered
            List<string> ticketTitles = new List<string>();
            foreach (string line in ticketLines)
            {   
                //select the line from which you want to start scrapping
                int y = codes.IndexOf(line);
                //ticket title
                ticketTitles.Add(codes[y + 1].Substring(codes[y + 1].IndexOf(">") + 1, codes[y + 1].Length - codes[y + 1].IndexOf(">") - 6));
                //created at
                ticketTitles.Add(codes[y+2].Substring(codes[y+2].IndexOf(">")+1, codes[y+2].Length - codes[y+2].IndexOf(">") - 6 )); 
            }



            //int x = 1;

        }