0

I am trying to extract the text within all the 'a' tags from this code, i get an error:

(AttributeError: ResultSet object has no attribute 'find_all'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?)

What am i doing wrong?

import json
import time
from datetime import datetime
from discord import Webhook, RequestsWebhookAdapter
from discord_webhook import DiscordWebhook, DiscordEmbed
import discord
from bs4 import BeautifulSoup
from discord.ext import commands

r = requests.get("https://www.hypedc.com/nz/nike-air-force-1-07-black-black-cw2288-001")
soup = BeautifulSoup(r.content, 'lxml')
size = soup.find('div', id="size-selector-tab-mobile-0")
size = size.find_all('li', class_='col-xs-6 col-sm-8 col-md-6 col-lg-4')
size = size.find_all('a').text
print(size)
3
  • 1
    Your code doesn't show any attempt to find 'a' tags. Commented Jan 8, 2021 at 0:13
  • "but this didn't work" what error message? Commented Jan 8, 2021 at 0:21
  • OK let me fix the question. Commented Jan 8, 2021 at 0:27

1 Answer 1

1

Here size.find_all('li', class_='col-xs-6 col-sm-8 col-md-6 col-lg-4') return a list. So you need to iterate it to get the size.

import requests
r = requests.get("https://www.hypedc.com/nz/nike-air-force-1-07-black-black-cw2288-001")
soup = BeautifulSoup(r.content, 'lxml')
size = soup.find('div', id="size-selector-tab-mobile-0")

size = size.find_all('li') # return list

for t in size:
    print(t.a.text.strip())
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, appreciate the help
please mark answer as accepted if it correctly solved your issue :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.