AttributeErrorr: у объекта 'NoneType' нет атрибута 'find_all' - PullRequest
0 голосов
/ 29 января 2020

Я пытаюсь скопировать веб-код (с вики-сайта) для получения названий стран из Википедии. Я получаю

"AttributeError: у объекта 'NoneType' нет атрибута 'find_all' '

и, следовательно, невозможно продолжить. Я добавляю свой код сюда и надеюсь найти руководство и помощь:

content = getHTMLContent('https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population')
tables = content.find_all('table')

for table in tables:
  print(table.prettify())

table = content.find('table', {'class': 'wikitable sortable'})
rows = table.find_all('tr')

#List of all links

for row in rows:
  cells = row.find_all('td')
  if len(cells) > 1:
    country_link = cells[1].find('a')
    print(country_link.get(href))
AttributeError                            Traceback (most recent call last)
<ipython-input-28-49edfe294aa4> in <module>()
      2 
      3 table = content.find('table', {'class': 'wikitable sortable'})
----> 4 rows = table.find_all('tr')
      5 
      6 #List of all links

AttributeError: 'NoneType' object has no attribute 'find_all'
...