如何从网站获取图像和链接到winform? [英] How to get images and links from website into winform?

查看:56
本文介绍了如何从网站获取图像和链接到winform?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hello codeproject guys:D,我想创建一个使用asp.net制作的网站的应用程序,我希望该应用程序将它的图像和文本放入我的程序,这样人们可以在我的程序中观看电影,我使用了chrome检查元素我看到可以获取图像的HTML代码

hello codeproject guys :D , i want to create an application to a website that made with asp.net , i want that application get it's images and text into my program so people can watch movies in my program, i used chrome inspect element i saw html code that can get image

<img src="http://www.kurdcinama.com/wenekan/5226101052016_KURD 1.jpg" alt="">



这个代码我可以得到一个图像,但它的html代码,我希望我的程序自动获取此代码,但首先扫描其他图像,以了解图像是否已经在程序中反复停止添加图像,我的声音很难但是......我需要告诉我一个方法然后我尝试以这种方式走路:)感谢帮助我



注意:我知道vb.net和c#语言,无论用哪种方式语言



我尝试过:



i试图让程序获取在asp.net中创建的网站上的信息


with this code i can get an image but its html code and i want my program get this code automatically but first scan other images to know if image already in program or not to stop adding image repeatedly, my sounds very hard but... i need to show me a way then i try to walk in this way :) thanks for helping me

note : i know vb.net and c# language, no matter which way with which language

What I have tried:

i trying to make program to get information on website that created in asp.net

推荐答案

好的 - 你需要从它的链接中获取图像网址 - 正则表达式会这样做:

Ok - you need to fetch the image url from it's link - a regex will do that:
string html = @"<img src=""http://cdn.codeproject.com.global.prod.fastly.net/App_Themes/CodeProject/Img/logo250x135.gif"" alt="""">";
Match m = Regex.Match(html, @"(?<=src="").+?(?="")");
if (m.Success)
    {
    string url = m.Value;
    ...
    }

然后您可以下载图像数据并将其转换为图像(如果需要):

Then you can download the image data and convert it to an image if you want:

using (WebClient webClient = new WebClient())
    {
    byte[] data = webClient.DownloadData(url);
    MemoryStream ms = new MemoryStream(data);
    Image im = Image.FromStream(ms);
    myPictureBox.Image = im;
    }

防止重复的最简单方法是使用图像数据(在数据库或类似文件中)存储URL,并检查URL是否已加载。如果它,我们现有的图像。如果不是,请从互联网上加载并保存。

The easiest way to prevent duplicates is to store the url with the image data (in a DB or similar) and check if the URL is already loaded. If it, us the existing image. If it isn't, load it from the internet and save it.


这篇关于如何从网站获取图像和链接到winform?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆