Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8847637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:14:15+00:00 2026-06-14T12:14:15+00:00

I am new to c# and I really need help with the following problem.

  • 0

I am new to c# and I really need help with the following problem. I wish to extract the photos urls from a webpage that have a specific pattern. For example I wish to extract all the images that have the following pattern name_412s.jpg. I use the following code to extract images from html, but I do not kow how to adapt it.

public void Images()
    {
        WebClient x = new WebClient();
        string source = x.DownloadString(@"http://www.google.com");

        HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
        document.Load(source);

        foreach(HtmlNode link in document.DocumentElement.SelectNodes("//img")
        {
          images[] = link["src"];
       }
}

I also need to write the results in a xml file. Can you also help me with that?

Thank you !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:14:16+00:00Added an answer on June 14, 2026 at 12:14 pm

    To limit the query results, you need to add a condition to your XPath. For instance, //img[contains(@src, 'name_412s.jpg')] will limit the results to only img elements that have an src attribute that contains that file name.

    As far as writing out the results to XML, you’ll need to create a new XML document and then copy the matching elements into it. Since you won’t be able to directly import an HtmlAgilityPack node into an XmlDocument, you’ll have to manually copy all the attributes. For instance:

    using System.Net;
    using System.Xml;
    
    // ...
    
    public void Images()
    {
        WebClient x = new WebClient();
        string source = x.DownloadString(@"http://www.google.com");
        HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
        document.Load(source);
        XmlDocument output = new XmlDocument();
        XmlElement imgElements = output.CreateElement("ImgElements");
        output.AppendChild(imgElements);
        foreach(HtmlNode link in document.DocumentElement.SelectNodes("//img[contains(@src, '_412s.jpg')]")
        {
            XmlElement img = output.CreateElement(link.Name);
            foreach(HtmlAttribute a in link.Attributes)
            {
                img.SetAttribute(a.Name, a.Value)
            }
            imgElements.AppendChild(img);
        }
        output.Save(@"C:\test.xml");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to objective C and I really need help with the following
I really need your help since I have a frustrating problem. I'm downloading data
Hello i am new in android and i really need help with something. I
I really need your help for this. I am relatively new to programming and
I'm new to java and really need some help. I created a command line
I'm new to MySQL so I really need some help with an issue I'm
Okay, I really need some help with this. I'm new with designing and stuff,
i m new to solr so i really need someone to help me understand
I have a following problem: I need to store generic objects with different type
this problem has driven me crazy and I really need you guys help. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.