[英]Why is my code not returning the right value?
我希望我的代码能输出剩余的库存,但是运行代码时却得到以下输出: <function get_sizes_in_stock at 0x10572f158>
import select
import requests
from bs4 import BeautifulSoup as bs
import random
session = requests.session()
def get_sizes_in_stock():
global session
endpoint = 'https://www.supremenewyork.com/shop/tops-sweaters/v4j0kn2qc/vtl376a1b'
response = session.get(endpoint)
soup = bs(response.txt, 'html.parser')
div = soup.find("select", {"name": "s"})
div = soup.find("select", {"name": "s"})
all_sizes = select.find_all("option")
sizes_in_stock = []
for size in all_sizes:
if "false" not in size["class"]:
size_id = size["value"]
sizes_in_stock.append(size_id.split("_")[1])
return sizes_in_stock
print(get_sizes_in_stock)
我希望代码能输出剩余的库存。 应该输出中和大
您应该调用print(get_sizes_in_stock())
,而不是print(get_sizes_in_stock)
。 get_sizes_in_stock
返回函数对象,而get_sizes_in_stock()
调用函数时不带任何参数。
所有方法都是python中的对象。
print(get_sizes_in_stock)
返回函数对象。 我认为您的意思是调用该函数:
print(get_sizes_in_stock())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.