尝试创建字典并追加到列表

时间:2020-08-25 11:22:42

标签: python list selenium dictionary

我正尝试从网站link抓取数据,当我们单击评论底部的“ Sterne Anzeigen”按钮时,我们找到了次级评分,并希望将其评分并存储在CSV文件。我能够执行诸如单击每个评论的按钮之类的操作,并编写代码以提取次级评级,如下所示:

-ObjC -weak_framework <the framework to ignore>

由于使用此代码,我得到了所有的评分值“ 5”,有人可以帮助我获得确切的评分吗?

预先感谢

2 个答案:

答案 0 :(得分:0)

尝试一下

   data=[]
   row={}  

    Stars=article.find_elements_by_class_name("index__factor__3Z15R")

   for item in Stars:
       key = item.find_element_by_class_name("index__title__W4hOp").text
       value = item.find_element_by_xpath("//*[@class='index__stars__2ads4 
       index__medium__1wpWb index__stars__3lgvx']").get_attribute("data-score")
       row.update(key=value)

   data.append(row)

答案 1 :(得分:0)

这是一种实现此目的的方法(使用#nullable enable public async Task<string> GetStringAsync(); ... public async void Main() { var theString = await GetStringAsync(); if (someCondition) { // If var inferred "string" instead of "string?" the following line would cause // warning CS8600: Converting null literal or possible null value to non-nullable type. theString = null; } } 模块和一些正则表达式逻辑):

requests

输出

import requests
from bs4 import BeautifulSoup
import re

response = requests.get("https://www.kununu.com/de/volkswagen/kommentare")
soup = BeautifulSoup(response.content)
scores = soup.find('div',{'class':re.compile('index__reviewBlock')})

output_dict = dict()
for el in scores.find_all('h4'):
    score_label = el.text
    score_stars = el.findNext('div').find('span',{'data-score':True}).get('data-score')
    output_dict[score_label] = int(score_stars)
    
相关问题