【问题标题】:FInding a HTML element from HTML source code [duplicate]从 HTML 源代码中查找 HTML 元素 [重复]
【发布时间】:2018-06-30 17:02:01
【问题描述】:

所以我试图找到一个 HTML 元素:

<a class="signout" href="https://www.dreamstime.com/logout.php">Sign out</a>

我的代码是:

 Dim thepage As String = postreqreader.ReadToEnd

                If thepage.Contains("<a href="https: //www.dreamstime.com/logout.php" class="signout">Sign out</a>") Then
                    good += 1
                    Label2.Text = "Good: " & good.ToString

                    If pencil = False Then
                        TextBox1.Text += currentaccount & vbNewLine
                        Me.Refresh()
                    End If

但是每次都会出现这个错误: OPEN ME

我尝试删除空间,但它一直出现错误说 逗号,")",或需要有效的表达式继续。

【问题讨论】:

  • 您需要在字符串中使用双双引号。所以Dim s = "a""b" 会导致 s 被设置为a"b
  • @Andrew Morton 你能把这个应用到我的代码上吗?我是 vb.net 的新手,所以很难理解你。
  • 应该是这样的:If thepage.Contains("&lt;a href=""https://www.dreamstime.com/logout.php"" class=""signout""&gt;Sign out&lt;/a&gt;") Then
  • 或者,更简单的方法:Dim ahref As String = "&lt;a class='signout' href='https://www.dreamstime.com/logout.php'&gt;Sign out&lt;/a&gt;".Replace("'", Chr(34)) 然后If thepage.Contains(ahref) Then ... ... 在这么多双双引号中不会“丢失”。 Chr(34) 是双引号的 ascii 代码。

标签: vb.net


【解决方案1】:

您没有正确地转义引号。 "A" = A, "" = , """" = "

或者让我们使用 * 以便更容易看到, *"**,第一个 * 表示开始,然后是 " 你的字符,然后是另一个 *,所以它知道字符结束,并且 * 作为字符串的结尾。

较长的字符串看起来像:

"some string ""is"" here"

这会导致:

some string "is" here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    • 2018-04-29
    • 2017-05-23
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多