我现在正在搜索网站上列出的所有购物中心
https://web.archive.org/web/20151112172204/http://www.simon.com/mall
使用Python和Scrapy。我想不出怎么提取文本“安克雷奇第五大道购物中心”。
<div class="st-country-padding">
<h4><a class="no-underline" href="/web/20151112172204/http://www.simon.com/search/alaska%2b(ak)" title="View Malls In Alaska">Alaska</a></h4>
<div>
<a href="/web/20151112172204/http://www.simon.com/search/anchorage,+ak" title="Malls in Anchorage, AK">Anchorage</a>:
<a href="http://www.simon.com/mall/anchorage-5th-avenue-mall" title="View Anchorage 5th Avenue Mall Website">Anchorage 5th Avenue Mall</a>
</div>
</div>我尝试了许多不同的尝试,包括
response.css("a::attr(title)").extract()但没有给我想要的东西。
请注意,Anchorage只是第一个商场的名称,所以我不能直接调用它,因为有大约200个不同的商场
发布于 2018-06-07 08:46:47
::attr(title)为您提供title属性的值。您需要的是文本,因此需要使用::text。
此外,似乎没有一种很好的方法来标识您想要的a元素,因为它没有任何区别于其他元素的东西,所以需要一些路径。如果这对你有效,请告诉我:
response.css(".st-country-padding > div > a:last-of-type::text").extract()https://stackoverflow.com/questions/50731368
复制相似问题