Reputation: 1711
I want to extract the download url from streamcloud in my C#-Program. Therefore I have to wait 10 seconds, click on a button and click on the player. Then I can extract the download url from the page-source.
My problem:
I have 2 ways to do this:
Automatic: I have to simulate a click on the button after 10 seconds. But my HtmlElement is always null.
Manually: I created a form with a WebBrowser-control. But this control didn't show for example the button. I think the WebBrowser-control is blocking all jscript-content. Is there a way, that the WebBrowser shows all content?
Or is there a other way to get the download-url?
Upvotes: 1
Views: 636
Reputation: 1180
Just use httpwebrequest or webclient:
public string ResolveStreamcloud(string url)
{
var client = new WebClient();
var reqParams = new NameValueCollection();
var response = client.DownloadString(url);
var regexObj = new Regex("<input.*?name=\"(.*?)\".*?value=\"(.*?)\">", RegexOptions.Singleline);
var matchResults = regexObj.Match(response);
while (matchResults.Success)
{
reqParams.Add(matchResults.Groups[1].Value, matchResults.Groups[2].Value);
matchResults = matchResults.NextMatch();
}
Thread.Sleep(10500);
byte[] responsebytes = client.UploadValues(url, "POST", reqParams);
string responsebody = Encoding.UTF8.GetString(responsebytes);
string resolved = Regex.Match(responsebody, "file: \"(.+?)\",", RegexOptions.Singleline).Groups[1].Value;
if (!String.IsNullOrEmpty(resolved))
{
return resolved;
}
else
{
throw new Exception("File not found!");
}
}
Upvotes: 0
Reputation: 61
If you want to do this on a machine with browser installed (IE or Firefox), you could use any framework for automated testing. WatiN is a good one.
Something like this:
using (var browser = new IE("http://www.streamcloud.com/YOUR_VIDEO_URL"))
{
browser.Button(Find.ByName("Play")).Click();
// wait for 10 seconds, or better use some WatiN functionality like WaitUntilExists
System.Threading.Thread.Sleep(10000);
// extract URL
var element = browser.Element(Find.ById("URL_CONTAINER_ID"));
string videoUrl = element.Text;
}
Upvotes: 1