This is my first time posting here - it's a great resource, I keep seeming to find solutions on here. I'm writing code to display an image gallery of YouTube videos on a website. I'm using Classic ASP to parse the RSS feed, and so far I've successfully got the thumbnail of the YouTube video. Now I'm trying to display only one of the 4 Jpegs - the URL of the YouTube RSS for thumbnails seems to be in the following format:
http://i.ytimg.com/vi/oh_OMkstzMQ/0.jpg
http://i.ytimg.com/vi/oh_OMkstzMQ/1.jpg
http://i.ytimg.com/vi/oh_OMkstzMQ/2.jpg
http://i.ytimg.com/vi/oh_OMkstzMQ/3.jpg
So, I was wondering if someone could suggest a way to only get 0.jpg from the feed? I'll post my code below:
<%
Dim xml, xhr, ns, YouTubeID, TrimmedID, GetJpeg, GetJpeg2, GetJpeg3, thumbnailUrl, xmlList, nodeList, TrimmedThumbnailUrl
Set xml = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
xml.async = False
xml.setProperty "ServerHTTPRequest", True
xml.Load("http://gdata.youtube.com/feeds/api/users/Shuggy23/favorites?orderby=updated")
If xml.parseError.errorCode <> 0 Then
Response.Write xml.parseError.reason
End If
Set xmlList = xml.getElementsByTagName("entry")
Set nodeList = xml.SelectNodes("//media:thumbnail")
For Each xmlItem In xmlList
YouTubeID = xmlItem.getElementsByTagName("id")(0).Text
TrimmedID = Replace(YouTubeID, "http://gdata.youtube.com/feeds/api/videos/", "")
For Each xmlItem2 In nodeList
thumbnailUrl = xmlItem2.getAttribute("url")
Response.Write thumbnailUrl & "<br />"
Next
Next
%>
Hope someone can help.
Thanks very much.
Douglas
If you just want to get 0.jpg from the thumbnail URL, try:
Right(thumbnailUrl, Len(thumbnailUrl) - InStrRev(thumbnailUrl, "/"))
If you want to just get the first thumbnail, you could use Exit For to bail out of the loop.
Related
Insert and resize a picture in an access report
Solution by Ms Isabel Smit aborts at first line of code.
My Report textbox [P1] populated by query has links to *.jpg files.
But code, Me.Image46.Picture = Me.P1.Value does not work. Get error msg Run-time error '94': Invalid use of Null.
Neither does Me!Image46.Picture = Me![P1] Run-time error '13': Type mismatch
Neither does Me!Image46.Picture = Me![P1].Value
Works if Me!Image46.Picture = hard coded filename but it defeats objective of each record to link to different filename.
Thank you
Updated Solution with validation:
I built your form and tested it. The only time I got it to fail was when the path to the image was invalid. Please try this:
Dim strFilename As String
strFilename = Me![P1].Value
If Len(Dir(strFilename)) > 0 Then
Me![Image7].Picture = strFilename
Me![Image7].Height = 9666 * Me![Image7].ImageHeight / Me![Image7].ImageWidth
Me![Image7].Width = 9666
Else
MsgBox "Image not found"
End If
This question is related to this one: Character encoding Microsoft.XmlHttp in Vbscript, but differs in one thing, the national characters are in the domain name, not only arguments.
The task is: download a page from the given URL.
I already solved problem of passing UTF8 string into VBScript by reading it from UTF8 encoded file through ADO.
But now when I try opening it MSXML2.ServerXMLHTTP returns error: The URL is invalid.
Here is VBScript code:
Set objStream = CreateObject("ADODB.Stream")
objStream.CharSet = "utf-8"
objStream.Open
objStream.LoadFromFile("fileWithURL.txt")
url = objStream.ReadText()
objStream.Close
Set XMLHttpReq = CreateObject("MSXML2.ServerXMLHTTP")
XMLHttpReq.Open "GET", url, False
XMLHttpReq.send
WEBPAGE = XMLHttpReq.responseText
If you put something like hxxp://россия.рф/main/page5.html into the UTF8 encoded fileWithURL.txt the script will raise an error while working ok with hxxp://google.com.
The workaround is to use ascii representation of the domain name - but I yet haven't found PunnyCode encoder for vbscript (apart from Chillkat which is an overkill for my task).
Will appreciate your help on the main problem or workaround.
I've made an amazing journey in to depth of my hard drive and found a code writen by / for Jesper Høy. This was the source code of SimpleDNS Plus' IDN Conversion Tool at that time.
Archive.org page snapshot: http://www.simpledns.com/idn-convert.asp
Archive.org file snapshot: idn-convert-asp.zip
You can also copy the whole code from this gist.
Create a function to convert URLs.
Function DummyPuny(ByVal url)
Dim rSegments : rSegments = Split(url, "/")
If UBound(rSegments) > 1 Then
rSegments(2) = DomainPunyEncode(rSegments(2))
End If
DummyPuny = Join(rSegments, "/")
End Function
Then convert your url before making the request.
XMLHttpReq.Open "GET", DummyPuny(url), False
I am trying to click a link on a page, it don't have any id and not having a unique class name. Only unique thing about the function is the onclick handler
<a href="#" onclick="closepopup('popup', 'popuphandler')" > </a>
I need to click this link via vbscript automation, for the same i tried the code as:
Set allLinks = ie.document.links
for j = 0 to allLinks.length-1
if allLinks(j).onClick = "closePopup(""popup"",""popupClose"")" then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
Next
But it is not working, please help.
Thanks in advance :)
You didn't specify what doens't work, finding the link or clicking it, in the first case:
onClick wil return something like
about:blank# function onclick()
{
closepopup('popup', 'popuphandler')
}
so you shoudl use instr to check if it is the right link
Dim HTMLDoc, XML, URL, table
Set HTMLDoc = CreateObject("HTMLFile")
Set XML = CreateObject("MSXML2.XMLHTTP")
URL = "your url"
With XML
.Open "GET", URL, False
.Send
HTMLDoc.Write .responseText
End With
Set allLinks = HTMLDoc.links
For each link in allLinks
if instr(link.onClick, "closepopup('popup', 'popuphandler')") then
link.click
exit for
end if
Next
Only the click won't work this way..
I would try to check if the closePupup is found in the actual javascript, like so:
'safety first
if not isnull(allLinks(j).onClick) then
if instr(allLinks(j).onClick.toString() , "closePopup(""popup"",""popupClose"")" ) > -1 then
allLinks(j).click
j = allLinks.length 'class name = blueButtonCenter
end if
end if
This assumens onClick delivers a string, (at least in javascript it does and in IE9 and Chrome this works)
I'm displaying an image like this:
<img src='counter.asp'>
counter.asp is doing a hit-counter do determine how often the image was displayed (I'll replace it with a modrewrite URL).
The problem: in the counter.asp script I need to send the actual .jpg image to the browser. How could this be done? I suppose I need to load the image through FSO, and then send it using Response.BinaryWrite - any ideas?
To read and output binary you can simply use the ADODB.Stream object.
See the ADODB.Stream MSDN Library:
http://msdn.microsoft.com/en-us/library/ms675032(VS.85).aspx
Here's an example I found from Experts Exchange as well:
Function ReadBinaryFile(strFileName)
on error resume next
Set oStream = Server.CreateObject("ADODB.Stream")
if Err.Number <> 0 then
ReadBinaryFile=Err.Description
Err.Clear
exit function
end if
oStream.Type = 1
oStream.Open
oStream.LoadFromFile strFileName
if Err.Number<>0 then
ReadBinaryFile=Err.Description
Err.Clear
exit function
end if
ReadBinaryFile=oStream.Read
oStream.Close
set oStream = nothing
if Err.Number<>0 then ReadBinaryFile=Err.Description
End Function
you can just redirect your counter.asp to the image you want..
<%
response.redirect("/virtual/path/to/yourimage.jpg")
%>
FSO cannot load a binary file, only text. You will need to use a 3th party component.
I want to load a ".tdm" file into DIAdem (National Instruments) with a VBScript but can't find how to do this. I have Dialog which opens a browse-window, which returns the path as a string. So I was hoping to have a function which would work something like this:
Call Data.Root.ChannelGroups.Load(myStringWithThePath)
Just noticed I got a tumbleweed-badge on this question. Here is the solution I found last week, so if anybody cares:
Set objDialog = CreateObject("UserAccounts.CommonDialog")
objDialog.Filter = "TDM-Datei(*.tdm)|*.tdm|All Files (*.*)|*.*"
objDialog.FilterIndex = 1
boolResult = objDialog.ShowOpen
If boolResult <> 0 Then
Call Data.Root.ChannelGroups.RemoveAll()
Call DataDelAll
Call DataFileLoad(objDialog.FileName)
End If