javascript-从页面源获取个人资料ID
作者:互联网
我想查找用户的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