python - 从“aria-label”标签中提取属性值
问题描述
我正在尝试从丝芙兰的网站上提取产品的评级。但是,当我尝试提取评级时,它并没有按照我想要的方式工作。我想我的问题是我不知道如何定位那个标签 b/c 它与我需要提取的其他数据相比具有不同的结构。请帮忙!
这里的图片是我想要提取的值。 在此处输入图像描述
我还在这里附上了我的代码。
final_products = [] #empty list to append the dictionary in to before passing in to a DataFrame
for i in range(0, len(link_list)):
#for i in urls.index:
current_url = link_list[i]
resource = requests.get(current_url)
current_data = resource.text
soup = BeautifulSoup(current_data, 'html.parser')
#gathering the data from the pages
try:
product = {}
product['Name'] = soup.find('span', {'class': 'css-0'}).text
product['Price'] = soup.find('div', {'class': 'css-slwsq8'}).text
product['Num_of_reviews'] = soup.find_all('span', {'class': 'css-2rg6q7'})[0].text
product['Num_of_Likes'] = soup.find('span', {'data-at': 'product_love_count'}).text
product['Rating'] = soup.find('a', {'aria-label'})
#append the empty list to later make in to a dataframe
final_products.append(product)
except:
pass
解决方案
推荐阅读
- c++ - 信号处理程序中的局部静态变量初始化是否安全(异步信号安全)?
- c - C Python.h API ImportError 与 OpenSSL
- javascript - Django 模板中的 Javascript
- opengl - 是否可以在同一个绘图调用中针对我也在采样的深度纹理进行深度测试?
- time - UTC 到中部时间的转换
- cookies - ngx-cookiesconsent 抛出错误通用类型'ModuleWithProviders
' 需要 1 个类型参数 - numpy - Google Colab Pro“您的会话在使用所有可用 RAM 后崩溃”在最简单的任务中
- python - 在 Django 中命名存档日期
- json - 临时 JSON 数据 - Swift
- html - 如何在 Visual Studio 中加载图像?