【发布时间】: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("<a href=""https://www.dreamstime.com/logout.php"" class=""signout"">Sign out</a>") Then -
或者,更简单的方法:
Dim ahref As String = "<a class='signout' href='https://www.dreamstime.com/logout.php'>Sign out</a>".Replace("'", Chr(34))然后If thepage.Contains(ahref) Then ...... 在这么多双双引号中不会“丢失”。Chr(34)是双引号的 ascii 代码。
标签: vb.net