在 python 3.6 中使用 beautifulsoup4 抓取产品信息的网站

While scraping a website for product information using beautifulsoup4 in python 3.6

我不明白如何只抓取文本,下面是我编写的用于抓取 itemTitle 和 itemPrice 的代码 如果这看起来很愚蠢,我很抱歉我是新手。

Input:

i_price = soup.find_all('span',{'class':'_89yzn'})
i_name = soup.find_all('span',{'class': ['_2tW1I']} )

for name,price in zip(i_name, i_price):
  print(name)
  print(price)

Output:

<span class="_2tW1I" data-aut-id="itemTitle">Wedding dress</span>
<span class="_89yzn" data-aut-id="itemPrice">Rs 4,000</span>

我只想显示文本,否则它看起来很难看。

IIUC:

i_price = soup.find_all('span',{'class':'_89yzn'})
i_name = soup.find_all('span',{'class': ['_2tW1I']} )

for name,price in zip(i_name, i_price):
  print(name.text)
  print(price.text)