hi guys, i have this worksheet, and after scraping a lot of records
i can no longer scrape since it's giving me error, i want it to scrape and save the next records (after 1048576) to the next worksheet
Option Explicit
'EDIT FIRST AND LAST NUMBER TO SCRAPE HERE***************
Const FIRST_NUMBER As Long = 1048574
Const LAST_NUMBER As Long = 1060000
Const ENGLISH As Long = 0 '1 FOR ENGLISH, 0 FOR ARABIC NAME
'********************************************************
Sub READ_Company_Info_Sub()
Dim xml As MSXML2.XMLHTTP60, Json As Object, i, h, realFirstNum As Long, pctCompl As Long
'Show progress bar
UserForm1.Show vbModeless
'snippet to skip scraping first company
If FIRST_NUMBER = 1 Then
realFirstNum = 2
Else
realFirstNum = FIRST_NUMBER
End If
For i = realFirstNum To LAST_NUMBER 'loop from first company to last
Set xml = New MSXML2.XMLHTTP60
With xml
Dim myLink As String
If ENGLISH = 1 Then
myLink = "{'languageId':1,'languageCode':'en-GB','keywords':'" & i & "','method':'CI'}"
Else
myLink = "{'languageId':2,'languageCode':'ar-AE','keywords':'" & i & "','method':'CI'}"
End If
.Open "POST", "https://www.mohre.gov.ae/services/AjaxHandler.asmx/LoadServiceResult", False
.setRequestHeader "Content-type", "application/json; charset=UTF-8" 'if this is not set, it returns useless HTML code
.Send myLink 'send the actual request
If Len(xml.responseText) < 15 Then GoTo nextCompany: 'if returned data is empty just skip this one
Set Json = JsonConverter.ParseJson(xml.responseText) 'parse the data
If ENGLISH = 1 Then
For h = 1 To 13
Cells(i, h) = Json("d")(CStr(Cells(1, h))) 'for each column, header is equal to JSON's titles, scrape accordingly
Next h
Else
Cells(i, 14) = Json("d")("CompanyName") 'for each column, header is equal to JSON's titles, scrape accordingly
End If
End With
nextCompany:
'calculate the percentage for progress bar and send update
pctCompl = (100 * (i - realFirstNum)) / (LAST_NUMBER - realFirstNum)
progress pctCompl
Next i
End Sub
Sub progress(ByVal pctCompl As Long)
UserForm1.Text.Caption = pctCompl & "% Completed"
UserForm1.Bar.Width = pctCompl * 2
DoEvents
End Sub
i can no longer scrape since it's giving me error, i want it to scrape and save the next records (after 1048576) to the next worksheet
Option Explicit
'EDIT FIRST AND LAST NUMBER TO SCRAPE HERE***************
Const FIRST_NUMBER As Long = 1048574
Const LAST_NUMBER As Long = 1060000
Const ENGLISH As Long = 0 '1 FOR ENGLISH, 0 FOR ARABIC NAME
'********************************************************
Sub READ_Company_Info_Sub()
Dim xml As MSXML2.XMLHTTP60, Json As Object, i, h, realFirstNum As Long, pctCompl As Long
'Show progress bar
UserForm1.Show vbModeless
'snippet to skip scraping first company
If FIRST_NUMBER = 1 Then
realFirstNum = 2
Else
realFirstNum = FIRST_NUMBER
End If
For i = realFirstNum To LAST_NUMBER 'loop from first company to last
Set xml = New MSXML2.XMLHTTP60
With xml
Dim myLink As String
If ENGLISH = 1 Then
myLink = "{'languageId':1,'languageCode':'en-GB','keywords':'" & i & "','method':'CI'}"
Else
myLink = "{'languageId':2,'languageCode':'ar-AE','keywords':'" & i & "','method':'CI'}"
End If
.Open "POST", "https://www.mohre.gov.ae/services/AjaxHandler.asmx/LoadServiceResult", False
.setRequestHeader "Content-type", "application/json; charset=UTF-8" 'if this is not set, it returns useless HTML code
.Send myLink 'send the actual request
If Len(xml.responseText) < 15 Then GoTo nextCompany: 'if returned data is empty just skip this one
Set Json = JsonConverter.ParseJson(xml.responseText) 'parse the data
If ENGLISH = 1 Then
For h = 1 To 13
Cells(i, h) = Json("d")(CStr(Cells(1, h))) 'for each column, header is equal to JSON's titles, scrape accordingly
Next h
Else
Cells(i, 14) = Json("d")("CompanyName") 'for each column, header is equal to JSON's titles, scrape accordingly
End If
End With
nextCompany:
'calculate the percentage for progress bar and send update
pctCompl = (100 * (i - realFirstNum)) / (LAST_NUMBER - realFirstNum)
progress pctCompl
Next i
End Sub
Sub progress(ByVal pctCompl As Long)
UserForm1.Text.Caption = pctCompl & "% Completed"
UserForm1.Bar.Width = pctCompl * 2
DoEvents
End Sub