Web Scraping code question, specific site

wittonlin

Board Regular
Joined
Jan 30, 2016
Messages
144
I can't for the life of my re-code a custom project of ours to deal with changes on the following website. I'm not 100% sure what the developer was going after in the code below, but maybe the site changed?? I removed part of the code that used to attempt to scrape whether the number is a cell or landline that doesn't appear to be available any longer. I hope I didn't mess anything up.

The code doesn't error. It's just that the result is ALWAYS the same data = "Call" << That's what it scrapes for every record now.

The following function queries a page like this 240-505-00## Silver Spring ✔ CALLER ID ✔ CALLER NAME check-caller.NET, from check-caller.net.

Rich (BB code):
Public Function checkcaller(ByVal x As Integer) 
    querys = "http://www.check-caller.com/1-" & ThisWorkbook.Sheets("PhoneToCity").Cells(x, 4).Value & ThisWorkbook.Sheets("PhoneToCity").Cells(x, 5).Value & "-" & ThisWorkbook.Sheets("PhoneToCity").Cells(x, 7).Value & "-index" 
    Dim xhr As MSXML2.XMLHTTP60 
    Dim HTML As MSHTML.HTMLDocument 
    Dim table As MSHTML.HTMLTable 
    Dim tableCells As MSHTML.IHTMLElementCollection 
    Dim imgs As Object, ink As Object 
     
    DoEvents 
    Set xhr = New MSXML2.XMLHTTP60 
    DoEvents 
    With xhr 
        DoEvents 
        .Open "GET", querys, False 
        .send 
        DoEvents 
        If .ReadyState = 4 And .Status = 200 Then 
            Set HTML = New MSHTML.HTMLDocument 
            HTML.body.innerHTML = .responseText 
        Else 
        End If 
        DoEvents 
    End With 
    DoEvents 
     
            citysss = HTML.getElementsByClassName("entry-content")(0).innerText 
    On Error Goto errngct 
    citys = Mid(HTML.getElementsByClassName("entry-content")(3).getElementsByTagName("td")(7).innerText, 1, InStr(1, HTML.getElementsByClassName("entry-content")(3).getElementsByTagName("td")(7).innerText, ",") - 3) 
    If err = 1 Then 
errngct: 
        sp = InStrRev(Mid(citysss, 1, InStr(1, citysss, ",")), " ") 
        sf = InStr(1, citysss, ",") - sp 
        citys = Mid(citysss, sp, sf) 
    End If 
     
    ThisWorkbook.Sheets("PhoneToCity").Cells(x, 11).Value = citys 
    err = 0 
    If err = 1 Then 
errng: 
        ThisWorkbook.Sheets("PhoneToCity").Cells(x, 11).Value = "unknown" 
    End If 
    Set xhr = Nothing 
    Set HTML = Nothing 
     
End Function


Using the html code there's two possible areas to scrape the data I need. (CITY)



1) <head>

<title>240-505-00## Silver Spring ✔ CALLER ID ✔ CALLER NAME check-caller.NET</title>



2)<div class="entry-content">

You want to know who called you? You want to know if the number 240-505-00## is safe or unsafe? check-caller.NET is a Real Time Directory with Caller ID lookup: White Pages & Yellow Pages. Add your feedback and your Voting about your call, please!

<br>Call from Silver Spring, MD / Maryland <div class="center">


If anyone knows the code to scrape the city from one or both locations above, please let me know.



Also posted: Web Scraping city code question, specific site
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

wittonlin

Board Regular
Joined
Jan 30, 2016
Messages
144
Crap the source html messed up the last two points!!

1) {head}
{title}240-505-00## Silver Spring ✔ CALLER ID ✔ CALLER NAME check-caller.NET{/title}

2){div class="entry-content"}
You want to know who called you? You want to know if the number 240-505-00## is safe or unsafe? check-caller.NET is a Real Time Directory with Caller ID lookup: White Pages & Yellow Pages. Add your feedback and your Voting about your call, please!
{br}Call from Silver Spring, MD / Maryland {div class="center"}
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,118,656
Messages
5,573,435
Members
412,529
Latest member
cTatch
Top