使用InStr搜索引号,空格,冒号等 [英] using InStr to search for quotes, spaces, colons, etc

查看:284
本文介绍了使用InStr搜索引号,空格,冒号等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是该问题的延续


this is a continuation of this question scrape data from web page source where url doesn't change

i'm now trying to search the scraped data and i'm not able to code it properly, it's not finding the text below

<span id="middleContent_lbName_county" style="font-weight:bold;">

i tried doing it like this

InStr(.Document.Body.innerHTML,"<span id=" & Chr(34) & "middleContent_lbName_county" & Chr(34) & " style=" & Chr(34) & "font-weight" & Chr(58) & "bold" & Chr(59) & "")

and i'm getting 0 in return.

this works

InStr(.Document.Body.innerHTML, "<span id=" & Chr(34) & "middleContent_lbName_county")

but it's not unique enough and i'm getting way too many results.

解决方案

I am a little unclear but there is an id there you can use and the string is the outerhtml of the element

.document.getElementById("middleContent_lbName_county").outerHTML

The info within is:

.document.getElementById("middleContent_lbName_county").innerText

Using this, .innerText, will return the facility name.

With your former code:

Option Explicit
Public Sub VisitPages()
    Dim IE As New InternetExplorer
    With IE
        .Visible = True
        .navigate "http://healthapps.state.nj.us/facilities/acSetSearch.aspx?by=county"

        While .Busy Or .readyState < 4: DoEvents: Wend

        With .document
            .querySelector("#middleContent_cbType_5").Click
            .querySelector("#middleContent_cbType_12").Click
            .querySelector("#middleContent_btnGetList").Click
        End With

        While .Busy Or .readyState < 4: DoEvents: Wend

        Dim list As Object, i  As Long
        Set list = .document.querySelectorAll("#main_table [href*=doPostBack]")
        For i = 0 To list.Length - 1
            list.item(i).Click

            While .Busy Or .readyState < 4: DoEvents: Wend

           ' Application.Wait Now + TimeSerial(0, 0, 3) '<== Delete me later. This is just to demo page changes
                Debug.Print .document.getElementById("middleContent_lbName_county").outerHTML
            'do stuff with new page
            .Navigate2 .document.URL             '<== back to homepage
            While .Busy Or .readyState < 4: DoEvents: Wend
            Set list = .document.querySelectorAll("#main_table [href*=doPostBack]") 'reset list (often required in these scenarios)
        Next
        Stop                                     '<== Delete me later
        '.Quit '<== Remember to quit application
    End With
End Sub


Some sample results:

这篇关于使用InStr搜索引号,空格,冒号等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆