Need help on if style statement

Sharid

Well-known Member
Joined
Apr 22, 2007
Messages
1,064
Office Version
  1. 2016
Platform
  1. Windows
I need to refine this part of my code, I was thinking maybe as an IF statement, So if

dd(1) = "@" then data is pasted into sheet1 column A starting at row 2
dd(2) = "http:" or "https" then data does into sheet1 column B starting at row 2


Problem is the (2).innerText and (3).innerText can have either or other text,

I don't want other text only emails and URLS in Sheet1

So Sheet1 "Scraper" should look like this

AB
EmailsURL
John@mysite.comhttp://mysite.com
Jane@gmail.comhttps://yoursite.com

<tbody>
</tbody>


Currently its all over the place.

Code:
'Variable for document or data which need to be extracted out of webpage, change innertext number if same class used
            Dim doc As HTMLDocument
            Set doc = ie.document
            dd(1) = doc.getElementsByClassName("_50f4")(2).innerText 
            dd(2) = doc.getElementsByClassName("_50f4")(3).innerText
            
            'On Error Resume Next
            'Paste in this sheet
            With Sheet1
                .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(, 2).Value = dd
            End With

Important - Data has to go in next blank row, so emails and urls match

Thanks for having a look
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi

I think I have got the first half, it extracts emails and places them in Sheet1 column A, start from row 2

I can't get it to pull the URLs as well. I am stuck on this bit, the URL is to go into column B, start from row 2

Code:
Sub scrapeHyperlinksWebsite()Dim ie As InternetExplorer
Dim html As HTMLDocument
Dim link As Object
Dim ElementCol As Object
Dim erow As Long
Application.ScreenUpdating = False
Set ie = New InternetExplorer
ie.Visible = True
ie.navigate "https://www.facebook.com/pg/SalemFordNH/about/?ref=page_internal"




Do While ie.readyState <> READYSTATE_COMPLETE
Application.StatusBar = "Loading website..."
DoEvents
Loop


Set html = ie.document


Set ElementCol = html.getElementsByTagName("a")
For Each link In ElementCol
If InStr(link, "mailto:") Then
erow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Cells(erow, 1).Value = link
Cells(erow, 1) = Right(link, Len(link) - InStr(link, ":"))
Cells(erow, 1).Columns.AutoFit
End If
Next
Set ie = Nothing
Application.StatusBar = ""
Application.ScreenUpdating = True


End Sub
 
Upvote 0

Forum statistics

Threads
1,213,554
Messages
6,114,280
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top