【发布时间】:2021-11-12 15:51:17
【问题描述】:
我是堆栈溢出的新手,我正在用 python 编写一个脚本,我有一个疑问我可以解决,我需要创建一个包含产品价格的变量,现在我已经收集了感谢网络抓取,以欧元为单位的十进制价格。
import bs4, requests
link = "https://hookpod.shop/products/hookpod-screw-adapter"
response = requests.get(link)
response.raise_for_status()
soup = bs4.BeatifulSoup(response.text, 'html.parster')
span_price = soup.find('span', class_='product__price')
输出给我的是:
<span class="product__price" data-product-price=""> €10.00 </span>
我需要获取金额(10.00 欧元)并将其转换为 int,有没有人可以帮助我,我真的需要它
【问题讨论】:
-
span_price = int(span_price.text.replace('€', ''))
标签: python python-3.x string web-scraping integer