scrapy 我想用刮刀从集装箱类刮锚一个

iq3niunx  于 2022-11-23  发布在  其他
关注(0)|答案(1)|浏览(111)
<div class="breadcrumbs">
<div class="container">
    
                        <a href="https://www.simple-dress.com/" title="Go to Home Page">Home</a>
                                    <span class="divider">&nbsp;</span>
        
    
                        <a href="https://www.simple-dress.com/cheap-special-occasion-dresses.html" title="">Special Occasion Dresses</a>
                                    <span class="divider">&nbsp;</span>
        
    
                        <a href="https://www.simple-dress.com/evening-dresses.html" title="">Evening Dresses</a>
                                    <span class="divider">&nbsp;</span>
        
    
                        <a href="https://www.simple-dress.com/formal-evening-dresses.html" title="">Formal Evening Dresses</a>
                                    <span class="divider">&nbsp;</span>
        
    
                        <strong>Deep V-neck Yellow Long Prom Dress Sleeveless Satin Evening Dress</strong>
                    
        </div>

我想从容器类中抓取第三个锚,但我无法抓取那个锚点。我使用response.css('.breadcrumbs div.container a').getall()这个选择器抓取所有锚点,但我只能抓取第一个锚点。我是初学者,需要帮助来抓取所有锚点。

vwoqyblh

vwoqyblh1#

使用XPath表达式非常简单。如果要按位置获取锚:

third_url = response.xpath('//div[@class="container"]/a[3]/@href').get()

如果你想通过文本链接获得锚:

evening_dresses_url = response.xpath('//div[@class="container"]/a[.="Evening Dresses"]/@href').get()

相关问题