Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. getting img tag src attribute values from a text file using C#

getting img tag src attribute values from a text file using C#

Scheduled Pinned Locked Moved C#
csharphtml
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Farhad Eft
    wrote on last edited by
    #1

    Hi, I have a text file that contains html tags. I like to use C# to read this file and list all the src attributes of tags. I was wondering how I can read through my file and list all of them. Thank you in advance for your time and consideration.

    OriginalGriffO 1 Reply Last reply
    0
    • F Farhad Eft

      Hi, I have a text file that contains html tags. I like to use C# to read this file and list all the src attributes of tags. I was wondering how I can read through my file and list all of them. Thank you in advance for your time and consideration.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Use an existing HTML parser: MIL HTML Parser[^] - let it handle the "donkey work" for you.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      F 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Use an existing HTML parser: MIL HTML Parser[^] - let it handle the "donkey work" for you.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        F Offline
        F Offline
        Farhad Eft
        wrote on last edited by
        #3

        That was a nice project but the problem is my content is coming from a json file, not a single html page.

        D 1 Reply Last reply
        0
        • F Farhad Eft

          That was a nice project but the problem is my content is coming from a json file, not a single html page.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          It would have been nice to include that important little tidbit in your original post. NewtonSoft's JSON library makes it easy to load and parse a JSON file. After that, you can use what OriginalGriff suggested.

          System.ItDidntWorkException: Something didn't work as expected. A guide to posting questions on CodeProject

          Click this: Asking questions is a skill. Seriously, do it.
          Dave Kreskowiak

          F 2 Replies Last reply
          0
          • D Dave Kreskowiak

            It would have been nice to include that important little tidbit in your original post. NewtonSoft's JSON library makes it easy to load and parse a JSON file. After that, you can use what OriginalGriff suggested.

            System.ItDidntWorkException: Something didn't work as expected. A guide to posting questions on CodeProject

            Click this: Asking questions is a skill. Seriously, do it.
            Dave Kreskowiak

            F Offline
            F Offline
            Farhad Eft
            wrote on last edited by
            #5

            Oh ok, thanks guys, I will give it a try then :thumbsup:

            1 Reply Last reply
            0
            • D Dave Kreskowiak

              It would have been nice to include that important little tidbit in your original post. NewtonSoft's JSON library makes it easy to load and parse a JSON file. After that, you can use what OriginalGriff suggested.

              System.ItDidntWorkException: Something didn't work as expected. A guide to posting questions on CodeProject

              Click this: Asking questions is a skill. Seriously, do it.
              Dave Kreskowiak

              F Offline
              F Offline
              Farhad Eft
              wrote on last edited by
              #6

              Actually in the end, I found it much easier for the task to be done in Python using the following code:

              import urllib
              f = urllib.urlopen("URL")
              s = f.read()
              f.close()

              from bs4 import BeautifulSoup
              soup = BeautifulSoup(s)

              inputTags = soup.find_all("img", attrs={"src":True})

              output = [ x["src"] for x in inputTags ]

              print output

              And yep I know this is C# forum! :D

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups