ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

javascript-从页面源获取个人资料ID

2019-11-19 19:32:30  阅读:335  来源: 互联网

标签:facebook-php-sdk phpexcel javascript php excel-vba


我想查找用户的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.下面是我在几个Profile链接(包括我的)上测试的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

如果您有网址列表,则可以将其保存在记事本中或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

标签:facebook-php-sdk,phpexcel,javascript,php,excel-vba
来源: https://codeday.me/bug/20191119/2038462.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有