使用bs4进行Web抓取时遇到问题

时间:2020-06-07 01:37:27

标签: python-3.x web-scraping beautifulsoup typeerror

在该程序中,我收到一条错误消息:“切片索引必须是整数或无整数,或具有 _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)

0 个答案:

没有答案