使用python scrapy进行刮擦-我需要返回同一标记中的所有值

kfgdxczn  于 2022-11-09  发布在  Python
关注(0)|答案(1)|浏览(129)

我试着擦除https://cryptorank.io/fundraising-platforms:我需要一个区块链信息:在Scrapy shell中我使用的代码是:

fetch('https://cryptorank.io/fundraising-platforms')

**FIRST EDIT**they changed .bZTNAB to .iyBlmE

response.css('.iyBlmE').get()

并返回:

'<td class="blockchain-icon__BlockchainIconWrapper-sc-1jbqlsx-1 bZTNAB"><a title="Solana" class="blockchain-icon__BlockchainIcon-sc-1jbqlsx-0 lktuZD"></a><a href="
/blockchains/solana"><img alt="Solana icon" class="styled__LinkIcon-sc-1dw6qb0-5 jpwBjO" src="https://img.api.cryptorank.io/coins/icon.solana1606979093056.png"></a
><a title="Ethereum" class="blockchain-icon__BlockchainIcon-sc-1jbqlsx-0 cvIVGk"></a><a href="/blockchains/ethereum"><img alt="Ethereum icon" class="styled__LinkIc
on-sc-1dw6qb0-5 jpwBjO" src="https://img.api.cryptorank.io/coins/icon.ethereum1524754015525.png"></a><a title="BNB" class="blockchain-icon__BlockchainIcon-sc-1jbql
sx-0 eJkzMZ"></a><a href="/blockchains/bnb"><img alt="BNB icon" class="styled__LinkIcon-sc-1dw6qb0-5 jpwBjO" src="https://img.api.cryptorank.io/coins/icon.binance%
20coin1645029040254.png"></a><a title="Polygon" class="blockchain-icon__BlockchainIcon-sc-1jbqlsx-0 dYSgum"></a><a href="/blockchains/matic-network"><img alt="Poly
gon icon" class="styled__LinkIcon-sc-1dw6qb0-5 jpwBjO" src="https://img.api.cryptorank.io/coins/icon.polygon1624610763534.png"></a><a title="Huobi Token" class="bl
ockchain-icon__BlockchainIcon-sc-1jbqlsx-0 cyYEun"></a><a href="/blockchains/huobi-token"><img alt="Huobi Token icon" class="styled__LinkIcon-sc-1dw6qb0-5 jpwBjO" 
src="https://img.api.cryptorank.io/coins/icon.huobi-token1524754545762.png"></a></td>'

但我需要所有名称区块链和这个信息是在这部分<a title="Polygon" class="blockchain-icon__BlockchainIcon-sc-1jbqlsx-0 dYSgum"></a>,如果我尝试:

response.css(".iyBlmE a::attr(title)").get()

只返回“Solana”,但我需要所有的区块链。

编辑添加一些图片以更好地解释:如果我使用response.css(".iyBlmE a::attr(title)").getall(),返回一个包含区块链列的所有itens的列表。

Image get .css using SelectorGadget extension
Image inspector the site
Run commands

egdjgwm8

egdjgwm81#

只有Solana图标有bZTNAB类,其余的都有不同的类。
我会使用下面的代码片段。
response.css('div[class^="blockchain-icon"] a::attr(title)).getall()

相关问题