Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python beautifulsoup 4选择一个类_Python_Html_Web Scraping_Beautifulsoup_Lxml - Fatal编程技术网

Python beautifulsoup 4选择一个类

Python beautifulsoup 4选择一个类,python,html,web-scraping,beautifulsoup,lxml,Python,Html,Web Scraping,Beautifulsoup,Lxml,我正在尝试制作一个工具来自动购买运动鞋。我正在网上查看运动鞋的供应情况。我是编程新手,这是我的第一个项目。多谢各位 def CheckStock(url, model): url = "http://www.adidas.com/us/pureboost-ltd-shoes/S80701.html?pr=product_rr&slot=3" headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10

我正在尝试制作一个工具来自动购买运动鞋。我正在网上查看运动鞋的供应情况。我是编程新手,这是我的第一个项目。多谢各位

def CheckStock(url, model):
  url = "http://www.adidas.com/us/pureboost-ltd-shoes/S80701.html?pr=product_rr&slot=3"
  headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
  html = requests.get(url, headers=headers)
  page = bs4.BeautifulSoup(html.text, "lxml")
  Sizes = page.select('.size-dropdown-block')
  Sizes[0].getText()
我知道正在选择页面,因为我使用命令page.title.string,它显示正确的标题。尝试执行大小时,我遇到以下错误

Traceback (most recent call last):
  File "<pyshell#146>", line 1, in <module>
    x[0].getText()
IndexError: list index out of range
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
x[0]。getText()
索引器:列表索引超出范围
大小为蓝色(可能是函数/方法暂时使用了不同的名称) 检查源代码中是否存在(.size下拉框)。 CTRL+U(大多数浏览器)或右键单击>查看页面源代码。 它可能是javascript生成的。如果是,则必须使用Selenium或其他自动浏览器。

大小为蓝色(可能是函数/方法,目前使用不同的名称) 检查源代码中是否存在(.size下拉框)。 CTRL+U(大多数浏览器)或右键单击>查看页面源代码。
它可能是javascript生成的。如果是,您必须使用Selenium或其他自动浏览器。

该功能适用于我,要求2.13.0,bs4.5.3。什么是
x
?大小[0]。getText()。抱歉,忽略x只是我测试多个代码的另一个实例。请向我们展示所有相关代码。如何初始化
x
?到底是什么导致了错误?这是我的代码,我使用的是Python shell。我使用大小[0]执行。getText()x只是大小。我不确定是什么原因导致了错误,很抱歉,python和编程新手该函数适合我,要求2.13.0,bs4.5.3。什么是
x
?大小[0]。getText()。抱歉,忽略x只是我测试多个代码的另一个实例。请向我们展示所有相关代码。如何初始化
x
?到底是什么导致了错误?这是我的代码,我使用的是Python shell。我使用大小[0]执行。getText()x只是大小。我不确定是什么原因导致了这个错误,很抱歉,这是python和编程的新手