我了解我需要进行自我搜索,但是我尝试并且不知道如何进行搜索。
我有很多这样的元素:
<li class="s-item " id="w4-items[32]">
<div class="s-item__wrapper clearfix">
<div class="s-item__image-section">
<div class="s-item__image">
<a href="https://example.com/1.jpg">
<div class="s-item__image-wrapper">
<div class="s-item__image-helper"></div>
<img class="s-item__image-img" alt="Apple Computer ..." src="https://example.com/1.jpg">
</div>
</a>
</div>
</div>
<div class="s-item__info clearfix">
<div class="s-item__title-hotness"></div>
<a class="s-item__link" href="https://example.com/abc">
<h3 class="s-item__title" role="text">Apple Computer ...</h3>
</a>
<div class="s-item__details clearfix">
<div class="s-item__detail s-item__detail--primary">
<span class="s-item__price">$14.24</span>
</div>
<div class="s-item__detail s-item__detail--primary">
<span class="s-item__shipping s-item__logisticsCost">Free shipping</span>
</div>
<div class="s-item__detail s-item__detail--primary">
<span class="s-item__hotness s-item__itemHotness"><span class="POSITIVE">HOT HOT</span></span>
</div>
</div>
</div>
</div>
</li>
使用此代码:
For Each telement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("li")
Dim Class1 As String = "POSITIVE"
Dim Class2 As String = "s-item__info"
If telement.OuterHtml.Contains(Class1) And telement.OuterHtml.Contains(Class2) Then
Dim conStr As String = telement.GetAttribute("innertext")
TextBox4.Text = TextBox4.Text & conStr & Environment.NewLine
End If
Next
结果:
Apple Computer...$14.24Free ShippingHOT HOT
Apple2 Computer...$15.00Free ShippingHOT HOT
Apple3 Computer...$16.00Free ShippingHOT HOT
为什么链接https://example.com/abc
不包含在结果中?
以及如何放置“ |”并删除“免费送货”,结果是这样的:
Apple Computer... | $14.24 | HOT HOT | https://example.com/abc
Apple2 Computer... | $15.00 | HOT HOT | https://example.com/abc
Apple3 Computer... | $16.00 | HOT HOT | https://example.com/abc
我有10多个这样的页面,那么如何为所有页面创建事件循环?