0

嗨,我想提取下面带有标签的 html 文件中的所有便利设施,alt="Has amenity / Allowed"例如电视、互联网……我做了以下代码:

var descriptionNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@id='amenities']//li//");

但它不会过滤其中alt="...."<img>内容,它只显示所有文本(在我的情况下是便利设施)。如果我添加("//div[@id='amenities']//li//img")它不会显示任何内容。我也尝试使用包含但没有结果。

<div id="amenities" style="display:none" class="details_content">
            <ul>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Smoking Allowed </p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Pets Allowed </p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>TV </p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Cable TV </p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Internet <a class="tooltip" title="Internet (wired or wireless)"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Wireless Internet <a class="tooltip" title="A wireless router that guests can access 24/7."><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Air Conditioning </p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Heating </p>
                    </li>
            </ul>
            <ul>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Elevator in Building </p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Handicap Accessible <a class="tooltip" title="The property is easily accessible.  Guests should communicate about individual needs."><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Pool <a class="tooltip" title="A private swimming pool"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Kitchen <a class="tooltip" title="Kitchen is available for guest use"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Parking Included </p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Doorman </p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Gym <a class="tooltip" title="Guests have free access to a gym"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Hot Tub </p>
                    </li>
            </ul>
            <ul>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Indoor Fireplace </p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Buzzer/Wireless Intercom </p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Breakfast <a class="tooltip" title="Breakfast is provided."><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Family/Kid Friendly <a class="tooltip" title="The property is suitable for hosting families with children."><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Doesn't have amenity / Not allowed" class="amenity-icon" height="17" src="//a1.muscache.com/airbnb/static/page3/v3/no_amenity-7229ab239bb2e3d81da7aa5034c265d4.png" title="Doesn't have amenity / Not allowed" width="17" />
                        <p>Suitable for Events <a class="tooltip" title="The property can accommodate a gathering of 25 or more attendees."><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Washer <a class="tooltip" title="Paid or Free, in building"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
                    <li>
                          <img alt="Has amenity / Allowed" class="amenity-icon" height="17" src="//a2.muscache.com/airbnb/static/page3/v3/has_amenity-3f3ba6d898588b24e37211888d98713f.png" title="Has amenity / Allowed" width="17" />
                        <p>Dryer <a class="tooltip" title="Paid or Free, in building"><img alt="Questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3" src="//a2.muscache.com/airbnb/static/icons/questionmark_hover-aaf1c7ee20bcff9b9ed6e8e5ef1af8e3.png" style="width:12px; height:12px;" /></a></p>
                    </li>
4

1 回答 1

1

它不是按属性过滤的,alt因为您没有告诉它。您需要应用一个谓词,就像您目前的情况一样id

//div[@id='amenities']//li[img/@alt='Has amenity / Allowed']

li这仅选择其内部图像具有所需alt属性的那些标签。

于 2012-06-26T12:55:43.547 回答