Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public strExtracted1 As String, strExtracted2 As String, strExtracted3 As String, strExtracted4 As String, strExtracted5 As String, strBody As String
  4. Public arrBody
  5. Public FollowingFound As String, FollowersFound As String, PostsFound As String, BioFound As String
  6.  
  7. Sub OpenIG()
  8.  
  9. 'set objects
  10.  
  11.     Dim arrUsers
  12.     Dim strUser As String
  13.     Dim rngArray As Range, UsedRange As Range, c As Range, rngUsers As Range, rngRange As Range
  14.     Dim p As Integer, x As Integer, q As Integer, i As Integer, intLR As Integer, g As Integer, k As Integer, h As Integer
  15.    
  16.     Dim DOC As MSHTML.HTMLDocument
  17.     Dim IE As SHDocVw.InternetExplorer
  18.  
  19.   On Error GoTo ErrHandler
  20.  
  21. p = 3
  22.  
  23. With ActiveSheet
  24.    
  25.         intLR = .Range("B2").CurrentRegion.Rows.Count
  26.  
  27.         Set rngUsers = .Range("B3:B" & intLR + 2)
  28.        
  29.         arrUsers = rngUsers
  30.            
  31. End With
  32.  
  33.  
  34. For x = 1 To UBound(arrUsers) - 1
  35.  
  36.     ActiveSheet.Range("C2").Value = "Processing " & x & "/" & UBound(arrUsers) - 1
  37.  
  38. FollowingFound = ""
  39. FollowersFound = ""
  40. PostsFound = ""
  41. BioFound = ""
  42.  
  43.  
  44.  
  45. RetryUser:
  46.    
  47.     strBody = ""
  48.    
  49.         strUser = arrUsers(x, 1)
  50.        
  51.         strUser = Trim(strUser)
  52.  
  53.     Set IE = New SHDocVw.InternetExplorer
  54.  
  55.     With IE
  56.  
  57.         strUser = arrUsers(x, 1)
  58.         strUser = Trim(strUser)
  59.  
  60.         .navigate "https://www.instagram.com/" & strUser
  61.         .Visible = False
  62.        
  63.         Application.Wait (Now + TimeValue("00:00:02"))
  64.  
  65.         Do While .Busy Or .readyState <> 4: DoEvents: Loop
  66.  
  67.         Set DOC = .document
  68.  
  69.         strBody = DOC.body.innerText
  70.  
  71.     End With
  72.    
  73.  
  74.  
  75.         IE.Quit
  76.        
  77.         Set IE = Nothing
  78.  
  79.         arrBody = Split(strBody, Chr(10))
  80.        
  81.         If UBound(arrBody) < 3 Then
  82.             Application.Wait (Now + TimeValue("00:00:01"))
  83.             GoTo RetryUser
  84.         End If
  85.        
  86.         For g = 1 To UBound(arrBody)
  87.        
  88.             If InStr(arrBody(g), "Sorry, this page isn't available") > 0 Then
  89.                
  90.                 strExtracted2 = "0"
  91.                 PostsFound = "0"
  92.                 FollowersFound = "0"
  93.                 FollowingFound = "0"
  94.                
  95.                 GoTo InsertBlankData
  96.            
  97.             End If
  98.        
  99.         Next g
  100.        
  101.         q = UBound(arrBody)
  102.  
  103.     With ActiveSheet
  104.    
  105. '        Set UsedRange = ActiveSheet.Range("Z1:Z" & q)
  106. '
  107. '        UsedRange = arrBody
  108. '
  109. '        Set UsedRange = ActiveSheet.Range("Z1:Z" & q)'
  110.  
  111.         h = 1
  112.         k = 0
  113.         Set rngRange = Range("Z1")
  114. '        Set UsedRange = UsedRange.Resize(UBound(arrBody))
  115. '        UsedRange.Value = Application.Transpose(arrBody)
  116. '
  117. '
  118. '        Application.ScreenUpdating = False
  119. '        Application.Calculation = xlCalculationManual
  120.        
  121.         For h = 1 To UBound(arrBody)
  122.        
  123.             Range("Z" & h) = arrBody(k)
  124.             k = k + 1
  125.        
  126.        
  127.         Next h
  128.        
  129.         Set rngRange = Range("Z1:Z" & h)
  130.        
  131.        
  132.         Dim s As String
  133.         For Each c In rngRange
  134.        
  135.             s = c.Value
  136.             If Trim(Application.Clean(s)) <> s Then
  137.             s = Trim(Application.Clean(s))
  138.             c.Value = s
  139.             End If
  140.            
  141.         Next
  142.  
  143.         Application.ScreenUpdating = True
  144.         Application.Calculation = xlCalculationAutomatic
  145.        
  146.         arrBody = rngRange
  147.        
  148.         ActiveSheet.Range("Z1:Z" & h).ClearContents
  149.        
  150.     End With
  151.    
  152.         For i = 1 To UBound(arrBody)
  153.  
  154.             If Trim(UCase(arrBody(i, 1))) = UCase(strUser) Then
  155.            
  156.                 Call FindPositions(i)
  157.                
  158.                 Call LocateData(i)
  159.                
  160.                 Exit For
  161.             End If
  162.            
  163.         Next i
  164.  
  165. InsertBlankData:
  166.  
  167.     With ActiveSheet
  168.    
  169.         .Range("E" & p).Value = BioFound
  170.         .Range("F" & p).Value = ExtractNums(PostsFound)
  171.         .Range("G" & p).Value = ExtractNums(FollowersFound)
  172.         .Range("H" & p).Value = ExtractNums(FollowingFound)
  173.        
  174.         p = p + 1
  175.        
  176.     End With
  177.  
  178.  
  179. Next x
  180.  
  181.  
  182. ErrHandler:
  183.  
  184. If Not IE Is Nothing Then
  185.     IE.Quit
  186.     Set IE = Nothing
  187. GoTo RetryUser
  188. End If
  189.  
  190. End Sub
  191.  
  192. Function ExtractNums(str As String) As String
  193.     Dim strVal As String
  194.     Dim i As Integer
  195.    
  196. '        If InStr(1, str, ".") > 0 Then
  197. '
  198. '            str = str & "00000"
  199. '
  200. '            GoTo Found
  201. '
  202. '        End If
  203.        
  204.         If InStr(1, str, ".") > 0 And InStr(1, str, "k") > 0 Then
  205.        
  206.             str = str & "00"
  207.            
  208.             GoTo Found
  209.            
  210.         End If
  211.        
  212.        
  213.         If InStr(1, str, "k") > 0 Then
  214.        
  215.             str = str & "000"
  216.            
  217.             GoTo Found
  218.            
  219.         End If
  220.        
  221.          If InStr(1, str, ".") > 0 And InStr(1, str, "m") > 0 Then
  222.        
  223.             str = str & "00000"
  224.            
  225.             GoTo Found
  226.            
  227.         End If
  228.        
  229.                    
  230.         If InStr(1, str, "m") <> 0 Then
  231.    
  232.    
  233.         str = str & "000000"
  234.  
  235.             GoTo Found
  236.            
  237.         End If
  238.  
  239. Found:
  240.     strVal = ""
  241.                                    '
  242.    For i = 1 To Len(str)
  243.         If Mid(str, i, 1) >= "0" And Mid(str, i, 1) <= "9" Then
  244.             strVal = strVal + Mid(str, i, 1)
  245.         End If
  246.     Next
  247.  
  248.                        
  249.     ExtractNums = strVal
  250. End Function
  251.  
  252. Sub LocateData(loc As Integer)
  253.  
  254. Dim b As Integer
  255.  
  256. For b = loc To UBound(arrBody, 1)
  257.  
  258.     If InStr(arrBody(b, 1), "post") > 0 Then
  259.    
  260.         PostsFound = arrBody(b, 1)
  261.     Exit For
  262.     End If
  263.    
  264. Next b
  265.  
  266. For b = loc To UBound(arrBody, 1)
  267.  
  268.     If InStr(arrBody(b, 1), "followers") > 0 Or InStr(arrBody(b, 1), "follower") Then
  269.    
  270.         FollowersFound = arrBody(b, 1)
  271.     Exit For
  272.         End If
  273. Next b
  274.  
  275. For b = loc To UBound(arrBody, 1)
  276.  
  277.     If InStr(arrBody(b, 1), "following") > 0 Then
  278.    
  279.         FollowingFound = arrBody(b, 1)
  280.        
  281.     Exit For
  282.         End If
  283. Next b
  284.  
  285. End Sub
  286.  
  287.  
  288. Sub FindPositions(loc As Integer)
  289.  
  290. Dim b As Integer
  291. Dim FoundPostsposition As Integer, FoundFollowersPosition As Integer, FoundFollowingPosition As Integer, LastPosition As Integer
  292. Dim MaxValue As Integer
  293. Dim BioPosition As Integer, k As Integer
  294.  
  295. For b = loc To UBound(arrBody, 1)
  296.    
  297.     If InStr(arrBody(b, 1), "post") > 0 Then
  298.    
  299.         FoundPostsposition = b
  300.     Exit For
  301.     End If
  302.    
  303. Next b
  304.  
  305.  
  306. For b = loc To UBound(arrBody, 1)
  307.  
  308.     If InStr(arrBody(b, 1), "followers") > 0 Or InStr(arrBody(b, 1), "follower") > 0 Then
  309.    
  310.         FoundFollowersPosition = b
  311.     Exit For
  312.         End If
  313. Next b
  314.  
  315. For b = loc To UBound(arrBody, 1)
  316.  
  317.     If InStr(arrBody(b, 1), "following") > 0 Then
  318.    
  319.         FoundFollowingPosition = b
  320.        
  321.     Exit For
  322.     End If
  323.    
  324. Next b
  325.  
  326.  
  327. For b = loc To UBound(arrBody, 1)
  328.  
  329.     If Len(arrBody(b, 1)) > 0 Then
  330.    
  331.         LastPosition = b
  332.        
  333.  
  334.     End If
  335.    
  336. Next b
  337.  
  338.  
  339. MaxValue = Application.Max(FoundPostsposition, FoundFollowingPosition, FoundFollowersPosition, LastPosition)
  340.  
  341. For b = loc + 1 To MaxValue
  342.  
  343.     If arrBody(b, 1) <> "No posts yet." And arrBody(b, 1) <> "" And arrBody(b, 1) <> "Follow" And arrBody(b, 1) <> "Verified" And b <> FoundPostsposition And b <> FoundFollowingPosition And b <> FoundFollowersPosition Then
  344.    
  345.         BioPosition = b
  346.         BioFound = arrBody(b, 1)
  347.        
  348.     Exit For
  349.     End If
  350.    
  351. Next b
  352.  
  353. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement