从页面源获取配置文件 ID

Getting profile id from page source

我想查找用户的 Facebook 个人资料 ID。我通过广泛的 google 搜索在 php 和 excel 中尝试了一些事情,但无法做到。

例如。 如果我转到 https://www.facebook.com/zuck,在源代码中,我会看到 "profile_id":4。这里的 4 是 Mark Zuckerberg 的个人资料 ID。同样,我需要识别少数人的个人资料 ID,并且我已经准备好他们的 Facebook 网址。做这个的最好方式是什么? PHP、Excel、Javascript 或任何其他语言。

请帮助我开始,因为我已经为此苦苦挣扎了两天。

谢谢

编辑: 在 excel 我做了这样的事情

Sub find()

Dim ie As Object
    Set ie = CreateObject("InternetExplorer.Application")
    With ie
        ie.Visible = False
        ie.Navigate "http://findfacebookid.com/"
    ie.Visible = True

    Do While ie.Busy
        Application.StatusBar = "Downloading information, lease wait..."
        DoEvents
    Loop

    pro = ie.Document.getElementsByID("profile_id")
End With


End Sub

免责声明:我不知道 php 也不与 Facebook Apis 合作。很有可能这些方法可以为您提供更好的东西


这是一个示例代码,可以在不到 2 秒的时间内为您提供 ID。下面是 Excel-VBA 中的代码,我在几个配置文件链接( 包括我的 )上测试了它并且有效。

Option Explicit

Sub Sample()
    Dim sURL As String
    Dim webSource As String
    Dim tmpString As String

    sURL = "https://www.facebook.com/zuck"

    With CreateObject("Microsoft.XMLHTTP")
        .Open "GET", sURL, False
        .send
        webSource = .responsetext
    End With

    tmpString = Split(webSource, "profile_id=")(1)
    tmpString = Split(tmpString, "&")(0)

    Debug.Print tmpString '<~~ Gives 4
End Sub

如果您有 URL 列表,则可以将其保存在记事本中或 excel 范围内。没关系。确保您读取数组中的所有数据,然后将其用于循环。

来自评论的跟进

I tried in both ways, if I keep inside the loop it works for only first id and fails on the next ones. If I keep outside the loop, then how can i open sURL from the .Open command? What I did was, For r = 1 To 150 sURL = Range("A" & r).Value and Next r at the end. Can you please edit the code and show me the correct way please? – Sabha 27 secs ago

我已经对代码进行了评论,但如果您仍有疑问,请直接提问 :)

Option Explicit

Sub Sample()
    Dim sURL As String
    Dim webSource As String, tmpString As String
    Dim i As Long, lRow As Long
    Dim ws As Worksheet

    '~~> This is the worksheet which has ids.
    Set ws = ThisWorkbook.Sheets("Sheet2")

    With ws
        '~~> Assuming that the urls are in Col A
        '~~> Find last row of col A
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row

        With CreateObject("Microsoft.XMLHTTP")
            For i = 1 To lRow
                sURL = ws.Range("A" & i).Value
                .Open "GET", sURL, False
                .send

                webSource = .responseText

                If InStr(1, webSource, "profile_id=") Then
                    tmpString = Split(webSource, "profile_id=")(1)
                    tmpString = Split(tmpString, ",")(0)
                ElseIf InStr(1, webSource, "profile_id"":") Then
                    tmpString = Split(webSource, "profile_id"":")(1)
                    tmpString = Split(tmpString, ",")(0)
                End If
                '~~> The ids will be written to Col B
                If tmpString <> "" Then ws.Range("B" & i).Value = tmpString
            Next i
        End With
    End With
End Sub