提取的数据未正确处理

时间:2019-03-01 20:52:16

标签: python-3.x beautifulsoup

我正在使用Python 3和Beautiful Soup 4从网站提取一些数据,然后将其显示在GUI上。每次运行时,ExtractedValues都等于无。我该如何解决此问题?

  labels = self.page.findAll("class_='label swap'")
  labelvalue = self.page.findAll("class_='val swap'")

  self.ExtractedValues={}  # Dictionary For Storing Data

  # Checking Data Is Ready For Extracting Automatically
  if len(labels)==len(labelvalue):
   for i in range(len(labels)):
    self.ExtractedValues[labels[i].text.replace('\n','')]=labelvalue[i].get_text().replace('\n','')
    self.ExtractedValues['temperature'] = self.page.find('span',{'class':'temp swap'}).get_text().replace('\n','')
    print (self.ExtractedValues['temperature'])
    self.ExtractedValues['summary'] = self.page.find('span',{'class':'summary swap'}).get_text().replace('\n','')
    print (self.ExtractedValues['summary'])
    self.ExtractedValues['next summary'] = self.page.find('span',{'class':'next swap'}).get_text().replace('\n','')
    print (self.ExtractedValues['next summary'])
    return self.ExtractedValues
  return

0 个答案:

没有答案