1

Пытаюсь сделать свой парсер python для сайта Animego, но у меня появляется ошибка:

TypeError: 'builtin_function_or_method' object is not iterable

Код парсера:

import requests
from bs4 import BeautifulSoup
import csv

def save():
    with open('example2.csv', 'w') as myfile:
        writer = csv.writer(myfile)
        writer.writerows(all)
    print("Writing complete")

def parse():
    url = "https://animego.org/"
    r = requests.get(url=url)
    soup = BeautifulSoup(r.content,'html.parser')
    divs = soup.findAll("div", {"class":"animes-list-item media"})
    all = []
    for div in divs:
        link = div.find("a",{"class":"d-block"}).get('href')
        title = div.find("div",{"class":"h5 font-weight-normal mb-1"}).text
        ser = div.find("span",{"class":"anime-year mb-2"}).find('a',{"class":"text-link-gray text-underline"}).text
        img = div.find("div",{"class":"anime-list-lazy lazy"}).get('data-original')
        sd = div.find("div",{"class":"description d-none d-sm-block"}).text
        all.append(div)

    save()

parse()
2
  • Вот какая ошибка Writing complete Traceback (most recent call last): File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module> start(fakepyfile,mainpyfile) File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start exec(open(mainpyfile).read(), main.__dict__) File "<string>", line 26, in <module> File "<string>", line 25, in parse File "<string>", line 8, in save TypeError: 'builtin_function_or_method' object is not iterable [Program finished] 10 дек 2021 в 7:33
  • 1. Вы не передаете значение all при вызове save() и не принимаете его в качестве аргумента в def save(); 2. Вы к all апперлите объекты BeautifulSoup, а не значения link, title etc...
    – Jack_oS
    10 дек 2021 в 8:25

1 ответ 1

0
  • В функцию записи файла нужно, видимо, передать значение:
def save(all):
    with open('example2.csv', 'w') as myfile:
        writer = csv.writer(myfile)
        writer.writerows(all)
  • В список all добавлять не объекты BeautifulSoup, а распарсенные строки:
all.append((link, title, ser, img, sd))
  • И все заработает:

введите сюда описание изображения

1
  • Огромное вам спасибо. 10 дек 2021 в 10:58

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.