您好我想提取标有alt="Has amenity / Allowed"
的html文件中的所有设施,例如电视,互联网......
我做了以下代码:
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>
答案 0 :(得分:1)
它没有按alt
属性进行过滤,因为您没有告诉它。您需要应用谓词,就像您目前用于id
:
//div[@id='amenities']//li[img/@alt='Has amenity / Allowed']
仅选择内部图片具有所需li
属性的alt
个标记。