我用python编写了一个脚本,可以从网页中提取不同项目的名称。我的剧本可以做得很好。有些物品不止一次出现。我想刮掉每件商品的外观编号。你知道吗
import requests
from bs4 import BeautifulSoup
baseUrl = 'https://www.etsy.com/shop/JpKrHk/sold?ref=pagination&page=2'
res = requests.get(baseUrl)
soup = BeautifulSoup(res.text,'lxml')
items = [item.get_text(strip=True) for item in soup.select(".v2-listing-card__info h2")]
print(len(items))
找出每个项目在列表中出现多少次的正确方法是什么?
除了使用注释中建议的Counter外,还可以使用dict理解和
list
的count()
方法:相关问题 更多 >
编程相关推荐