-3

I wanna be able to get the "The Merinda Flat Sandal In Silver" this is in a form this is the code <p class="product_note">The Merinda Flat Sandal In Silver</p> I wanna copy it to a string like in the code below but to get the text and not the value


string id = "https://www.factory54.co.il/products/Logo-canvas-sneakers-in-White-No-167";
            Console.WriteLine(HtmlAgi(id)); 

        }
        public static string HtmlAgi(string url)
        {

            var Webget = new HtmlWeb();
            var doc = Webget.Load(url);
            HtmlNode ourNode = doc.DocumentNode.SelectSingleNode(("//form[@class]"));

            if (ourNode != null)
            {


                return ourNode.GetAttributeValue("class", "");

            }
            else
            {
                return "not fount";
            }

        }```
```<div class="produtshow clearfix">
                                                                                            <h1 id="manufacturer_header"><a href="https://www.factory54.co.il/designers/stuart-weitzman" title="Stuart Weitzman">Stuart Weitzman</a>                                    <p class="product_note">The Merinda Flat Sandal In Silver</p>
                                </h1>

</div>```
And here is where the text is in the html file (this is located in a form)

Eden Ichak
  • 13
  • 6
  • This need more explanation. Where is this HTML coming from. What kind of C# program are you running? – Jasper Kent Mar 22 '20 at 14:41
  • This is just an example for an html form. I'm running HttpRequest but before I do I wanna know the action thats why i need this I mean the program gets URL and copies the value of action – Eden Ichak Mar 22 '20 at 14:43
  • Still not clear. Let me put it another way: why can't you just read the HTML into your C# program and search through it for the text you want? – Jasper Kent Mar 22 '20 at 14:54
  • Sounds great to me how do i do this|? – Eden Ichak Mar 22 '20 at 15:00
  • Try this: https://stackoverflow.com/questions/846994/how-to-use-html-agility-pack – Jasper Kent Mar 22 '20 at 17:26
  • Thank you but I'm trying to get as input the URL of the html site and then read it and find the action value do u know how can i do this? – Eden Ichak Mar 22 '20 at 18:08
  • Sorry, I can't help if you won't explain the problem more clearly. – Jasper Kent Mar 22 '20 at 18:13
  • I am sorry here is a little more clear explanation – Eden Ichak Mar 22 '20 at 18:26
  • Check the post again please – Eden Ichak Mar 22 '20 at 18:30
  • That's a lot better, but for future reference it would be better still to have left in something of the original question. The current question makes little sense to anyone who hasn't been following its evolution. – Jasper Kent Mar 22 '20 at 18:48
  • I'd suggest you revert this to the original question, otherwise the answer will make no sense to anyone looking in future. The point is not simply to answer questions, but to build up a resource for others with similar questions in future. – Jasper Kent Mar 24 '20 at 08:46

1 Answers1

0

Change the SelectSingleNode line to:

HtmlNode ourNode = doc.DocumentNode.SelectSingleNode(("//form[@action]"));

To read multiple for elements, use:

static void Main(string[] args)
{
    string id = "https://www.factory54.co.il/products/Logo-canvas-sneakers-in-White-No-167";
    HtmlAgi(id);
}

public static void HtmlAgi(string url)
{
    var Webget = new HtmlWeb();
    var doc = Webget.Load(url);
    var ourNodes = doc.DocumentNode.SelectNodes(("//form[@action]"));

    foreach (var node in ourNodes)
        Console.WriteLine(node.GetAttributeValue("action", ""));
}  

It's down to you to determine which one your want.

Jasper Kent
  • 3,546
  • 15
  • 21
  • First of all thanks for helping out, I got an output but not the output I wanted maybe it's because there's more then one form/action in this html anyway to solve this? – Eden Ichak Mar 22 '20 at 18:54
  • I got another question I updated the post if u can help I'll appreciate – Eden Ichak Mar 23 '20 at 21:06
  • Post it as a new question and I'll be happy to give it a go. Makes life easier for everyone. – Jasper Kent Mar 23 '20 at 22:36