解析单选按钮名称仅显示一个值 [英] Parsing Radio button name only bringing up one value

查看:47
本文介绍了解析单选按钮名称仅显示一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一些代码,以通过一些单选按钮来解析名称.

I have written some code to parse the name from some radio buttons.

<div id="First" class="Size-Inputs"> 
<input rel="8" type="radio" value="13051374" name="idProduct-13051359"/> <span rel="L">L</span>
<input rel="8" type="radio" value="13051373" name="idProduct-13051359"/> <span rel="M">M</span>
<input rel="8" type="radio" value="13051372" name="idProduct-13051359"/> <span rel="S">S</span>
<input rel="8" type="radio" value="13051375"name="idProduct-13051359"/> <span rel="XL">XL</span> </div>

当我尝试解析span rel以获取大小名称(例如L,M,S,XL)时遇到的问题是,它只给出了四次L值.

The problem which I am having when I try to parse the span rel to get the size names eg L,M,S,XL it is only coming up with the value L four times.

我正在使用的代码是;

The code I am using is;

HtmlNodeCollection link = doc.DocumentNode.SelectNodes("//*[@id='First']/input");
if (link != null)
{
    foreach (HtmlNode item in link)
    {
        string name = item.SelectSingleNode("//*[@id='First']/span").InnerText;
        Console.WriteLine(name);
    }
    Console.ReadLine();
}

我只是想知道为什么它只拾取一个值并打印四次,以及如何使它拾取每个变量输入的跨度.感谢您提供的任何帮助

I was just wondering why the it is only picking up one value and printing it four times and how can you make it pick up the span rel for each of the variant input. Thanks for any help which you can provide

推荐答案

似乎您不需要<input>元素,但需要<span>元素.并且<span>不是<input>的子级.因此,假设这不是拼写错误或粘贴错误,则可以直接选择<span>,而无需先选择<input>元素:

It seems that you don't need <input> element but <span> element. And <span> is not child of <input>. So assuming that it isn't typo or paste error, you can select <span> directly without selecting <input> element first :

HtmlNodeCollection link = doc.DocumentNode.SelectNodes("//*[@id='First']/span");
if (link != null)
{
    foreach (HtmlNode item in link)
    {
        string name = item.InnerText;
        Console.WriteLine(name);
    }
    Console.ReadLine();
}

这篇关于解析单选按钮名称仅显示一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆