Я не могу найти, почему мои 2 переменные возвращают "None", пока они определены в циклах.
Even Печать ".span.text.find (" France "))" didn ' т работа. Я думаю, что мои две петли не выполнены. Я не знаю почему.
Я тоже сомневаюсь, что проблема в супе. Действительно, иногда это работает. иногда не там, где я не трогаю код.
#IMPORT DES LIBRAIRIRES
import bs4
import requests
import re
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
import urllib.request
from bs4 import BeautifulSoup
from datetime import date
#VARIABLES
date_jour = date.today()
URL ="https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6"
# Chrome session USING SELENIUM
#driver = webdriver.Chrome("C:/Users/33769/Desktop/chromedriver.exe")
#driver.get(URL)
#driver.implicitly_wait(100)
#soup=bs4.BeautifulSoup(driver.page_source,"html.parser")
#USING REQUESTS
req = requests.get('https://en.wikipedia.org/wiki/Python_(programming_language)')
soup=bs4.BeautifulSoup(req.text,"html.parser")
nb_infected = None
nb_deaths = None
#Infected Cases France
for span in soup.find_all('div',{'class':'flex-fluid list-item-content overflow-hidden'})[:12]:
if span.text.find("France")!= -1:
nb_infected = span.text.replace('\n\n','')
nb_infected = nb_infected.replace('\xa0','')
nb_infected = nb_infected.replace('France','')
print("OKKKKKK")
else:
print("NOT OK")
print(span.text.find('France')) # NOT EXECUTED... WHY ???
#Deaths France
for span in soup.find_all('div',{'class':'flex-fluid list-item-content overflow-hidden'})[420:480]:
if span.text.find("France")!= -1:
nb_deaths = span.text.replace('\n\n','')
nb_deaths = nb_deaths.replace('\xa0','')
nb_deaths = nb_deaths.replace('deaths\nFrance','')
print("To conclude, in France, there are " + str(nb_infected) + " infected individuals and " + str(nb_deaths) + " deaths" )
#ONLY THIS LAST FINE WORKS....