import requests
from bs4 import BeautifulSoup as bs
session = request.session()
def get_sizes_in_stock():
global session
endpoint = "https://www.off---white.com/en/SE/men/products/omia065r208000010100#"
response = session.get(endpoint)
soup = bs(response.text,"html.parser")
ul = soup.find("ul",{"class":"styled-radio"})
all_sizes = ul.find_all("li")
sizes_in_stock = []
for size in all_sizes:
if "availability not_on_sale" not in size["class"]:
size_id = size["id"]
sizes_in_stock.append(size_id.split("_")[1])
return sizes_in_stock
print(get_sizes_in_stock())
收到的错误是:
Traceback (most recent call last):
File "C:\Users\arvid\Desktop\python tings\owbot.py", line 4, in <module>
session = request.session()
NameError: name 'request' is not defined
>>>
答案 0 :(得分:0)
您在requests
中拼写了session = request.session()
。
该库为requests
(复数)