Reputation: 297
When I use FireFox for "https://twitter.com/search?q=vbs", all works well and I see the tweets (without ever logging on). But, when I try to use the simplest VBS-scripting way with XMLHTTP, it seems like I am declared a mobile user to Twitter and I don't get search results. So, how can I change my VBS code below to make this work? In principle, it seems like I should be able to set some objXMLHTTP property to spoof any browser, but then again, Microsoft probably wouldn't give me this freedom so easily. Any comments would be great!
strFileURL = "https://twitter.com/search?q=vbs"
strHDLocation = "C:\Users\me\webpages\saved_tweets.html"
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send()
if objXMLHTTP.Status = 200 then
Set objADOStream = CreateObject("ADODB.Stream")
objADOStream.Open
objADOStream.Type = 1
objADOStream.Write objXMLHTTP.ResponseBody
objADOStream.Position = 0
Set objFSO = Createobject("Scripting.FileSystemObject")
if objFSO.Fileexists(strHDLocation) then objFSO.DeleteFile strHDLocation
Set objFSO = Nothing
objADOStream.SaveToFile strHDLocation
objADOStream.Close
Set objADOStream = Nothing
end if
Set objXMLHTTP = Nothing
Upvotes: 0
Views: 1679
Reputation: 6251
Maybe you could fake a User Agent (browser) in your HTTP request so that Twitter will consider your browser as a desktop with something like this :
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:23.0) Gecko/20131011 Firefox/23.0"
objXMLHTTP.send()
Upvotes: 2
Reputation: 200293
Would using the mobile search page be an option?
strFileURL = "https://mobile.twitter.com/search?q=vbs"
Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", strFileURL, false
objXMLHTTP.send
Upvotes: 1