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

  • SEARCH
  • Home
  • 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 7571503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:41:25+00:00 2026-05-30T15:41:25+00:00

Hi so i am trying to parse a webpage with HTML Agilty Pack to

  • 0

Hi so i am trying to parse a webpage with HTML Agilty Pack to get the src of an image. This is the structure of the page.

<div class="post_body"> 
    <div style="text-align: center;"> 
        <a href="http://www.engadget.com/2012/02/29/qualcomm-windows-8/">
            <img src="http://www.blogcdn.com/www.engadget.com/media/2012/02/201202297192-1330536971.jpg" style="border-width: 0px; border-style: solid; margin: 4px;">
        </a>
    </div>
<div>

Now I am using this code to attempt to get the src

HtmlWeb hw = new HtmlWeb();
            HtmlDocument doc = hw.Load("http://www.engadget.com/2012/02/29/qualcomm-windows-8");

            HtmlNode baseNode = doc.DocumentNode.SelectSingleNode("//div[@class='post_content permalink ']");
            string Description = baseNode.SelectSingleNode("//div[@class='post_body']").InnerText.Replace("\n", "").Replace("\r", "").Trim();

            string href = baseNode.SelectSingleNode("//div[@class='post_body']//img[@src]").InnerText;

However the string is always being returned null :/

Any ideas maybe i have a bad xpath expression?

  • 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-05-30T15:41:26+00:00Added an answer on May 30, 2026 at 3:41 pm

    Any ideas maybe i have a bad xpath expression?

    Yes, there are a few problems:

    //div[@class='post_content permalink ']
    

    This selects nothing, because in the provided document there isnt a div with class attribute, whose value is 'post_content permalink '

    SelectSingleNode("//div[@class='post_body']//img[@src]").InnerText;  
    

    The img element, even if such is found, has no children — thus no innerText.

    Solution:

    You want something like this:

    HtmlNode  img = doc.DocumentNode.SelectSingleNode(//div[@class='post_body']//img[@src])
    
    String srcUrl = img.Attributes["src"].Value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse the HTML of a webpage that requires being logged in.
i'm trying to get web-page data in string that than i could parse it.
I am trying to parse the HTML of a webpage to DOM by loading
I'm trying to download and parse the HTML of a web page. Recently, the
I am trying to get HTML code from a webpage that is not in
I'm trying to get a list of stations from this webpage - https://web.barclayscyclehire.tfl.gov.uk/maps I
I'm trying to parse a webpage using Java with URLConnection. I try to set
With BeautifulSoup 3.1.0.1 and Python 2.5.2, and trying to parse a web page in
I'm trying to make a web scraper that will parse a web-page of publications
Trying to parse an HTML document and extract some elements (any links to text

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.