JoeyCK
JoeyCK

Reputation: 1402

Get CSS bg image from web page on VB.NET

I have the code of a web page and it contains lots of "divs" with backgroud images like this:

style="BACKGROUND-IMAGE: url(/images/image1.jpg)"

Is there an easy way in VB.NET to get all the URLs from bg images from the page?

Upvotes: 0

Views: 409

Answers (1)

Prescott
Prescott

Reputation: 7412

You can start by getting the HTML by using a WebClient:

Dim client As New WebClient()

        ' Add a user agent header in case the 
        ' requested URI contains a query.
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)")

        Dim data As Stream = client.OpenRead(args(0))
        Dim reader As New StreamReader(data)
        Dim s As String = reader.ReadToEnd()
        Console.WriteLine(s)
        data.Close()
        reader.Close()

From here you can parse that string (s) looking for something that matches "BACKGROUDN-IMAGE: {*}" - someone else will need to chime in, my regex-fu is horrible. Regex.Matches() - MSDN

Upvotes: 1

Related Questions