在该程序中,我收到一条错误消息:“切片索引必须是整数或无整数,或具有 _index 方法”。有人知道为什么吗?预先感谢!
import requests, html.parser
from bs4 import BeautifulSoup
link = 'https://www.amazon.com/dp/B005EWTL7C'
headers = {"User-Agent" :'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}
page = requests.get(link, headers=headers)
soup = BeautifulSoup(page.content, 'html.parser').encode("utf-8")
price = soup.find("span", "a-size-medium a-color-price priceBlockSalePriceString").get_text()
#converted = price[0:4]
#print(converted)