Jak mogę naprawić następujący AttributeError: Obiekt „dict” nie ma atrybutu „text”
Programuję już od kilku miesięcy. Obecnie badam, jak zautomatyzować pewne rzeczy w projekcie. Moim celem jest wyczyszczenie tekstu, src i href oraz zapisanie danych w bazie danych mojej witryny, ale kiedy próbuję, pojawia się ten błąd
AttributeError: 'dict' object has no attribute 'text'
ale tak jest. to jest mój kod. Stworzyłem funkcję
def get_world_too():
url = 'http://www.example.com'
html = requests.get(url, headers=headers)
soup = BeautifulSoup(html.text, 'html5lib') titles = soup.find_all('section', 'box')[:9]
entries = [{'href': box.a.get('href'),
'src': box.img.get('src'),
'text': box.strong.a.text,
'url': url
} for box in titles]
return entries
potem to zrobiłem
def noindex(request):
world = get_world_too() for entry in world:
post = Post()
post.title = entry.text
post.image_url = entry.src
# post.url = entry.url
# post.link = entry.href
# post.description = entry.description
#
# d = datetime.datetime(*(entry.published_parsed[0:6]))
# date_string = d.strftime('%Y-%m-%d %H:%M:%S')
#
# post.publication_date = date_string
post.save() template = "blog/post/noindex.html"
context = { }
return render(request, template, context)
Czy atrybut tekstu nie jest częścią mojej funkcji? Wtedy jeśli spróbuję skomentować tekst, to mi powie
AttributeError: 'dict' object has no attribute 'src'
jak mogę to naprawić, aby potrzebne dane były przechowywane w mojej bazie danych bez żadnych błędów? Używam django, jeśli ma to znaczenie.
Nie znaleziono powiązanych wyników
Zaproszony:
Aby odpowiedzieć na pytania, Zaloguj się lub Zarejestruj się
2 odpowiedzi
Anonimowy użytkownik
Potwierdzenie od:
Po prostu nie tak
Anonimowy użytkownik
Potwierdzenie od:
Jeśli wpis jest słownikiem, możesz użyć
entry['key1']