0
J'essaie de compter le mot sur la page d'accueil de google. Mais j'ai AttributeError sur la scène initiale.Python-AttributeError: l'objet 'NoneType' n'a pas d'attribut 'lower'
Mon code est ->
import requests
from bs4 import BeautifulSoup
import operator
def main(url):
word_list=[]
source_code=requests.get(url).text
soup=BeautifulSoup(source_code,'lxml')
for post_text in soup.findAll('a'):
content=post_text.string
words=content.lower().split()
for each_word in words:
print(each_word)
word_list.append(each_word)
main('https://www.google.co.in/?gfe_rd=cr&dcr=0&ei=2-nqWavnB4WN8Qf4n7eQAw')
Ma sortie est ->
images
maps
play
youtube
news
gmail
drive
Traceback (most recent call last):
File "word_freq.py", line 18, in <module>
main('https://www.google.co.in/?gfe_rd=cr&dcr=0&ei=2-nqWavnB4WN8Qf4n7eQAw')
File "word_freq.py", line 13, in main
words=content.lower().split()
AttributeError: 'NoneType' object has no attribute 'lower'
Vous devez ajouter un 'si le contenu n'est pas none' après' content = POST_TEXT. string', car il n'est pas nécessaire que toutes les balises 'a' aient une chaîne de caractères. – ZdaR