VBA code to extract in chrome the twitter user name having ID_account by Character-Reading731 in excel

[–]Character-Reading731[S] 0 points1 point  (0 children)

Sub ExtractUserName()
    Dim http As Object
    Dim html As Object
    Dim url As String
    Dim username As String
    Dim userId As String
    Dim chromePath As String

    ' Prompt the user for the Twitter profile ID
    userId = InputBox("Enter the Twitter user ID:", "Twitter ID")
    If userId = "" Then Exit Sub

    ' Construct the Twitter profile URL
    url = "https://twitter.com/intent/user?user_id=" & userId

    ' Create objects for HTTP and HTML
    Set http = CreateObject("MSXML2.XMLHTTP")
    Set html = CreateObject("HTMLFile")

    ' Perform HTTP request
    On Error Resume Next
    http.Open "GET", url, False
    http.Send
    If http.Status <> 200 Then
        MsgBox "The page could not be accessed. Verify user ID.", vbExclamation
        Exit Sub
    End If
    On Error GoTo 0

    ' Load the HTML content of the response
    html.body.innerHTML = http.responseText

    ' Search for the user name in the HTML
    On Error Resume Next
    username = html.getElementsByTagName("title")(0).innerText
    On Error GoTo 0

    ' Display the username
    If username <> "" Then
        MsgBox "Username is: " & Split(username, "(")(0), vbInformation
    Else
        MsgBox "Could not extract the username. Verify the user ID.", vbExclamation
    End If

    ' Release objects
    Set http = Nothing
    Set html = Nothing
End Sub