python-3.x - BeautifulSoup标签
问题描述
解决方案
内容是动态提供的,因此您不会以这种方式获得它requests
- 看看这段selenium
代码。
要摆脱文本和空格,您可以执行以下操作:
.get_text(strip=True).replace('Was: ','')
例子
from selenium import webdriver
from bs4 import BeautifulSoup
import time
url = "https://www.petshop.co.uk/Dog"
driver = webdriver.Chrome('C:\Program Files\ChromeDriver\chromedriver.exe')
driver.get(url)
time.sleep(3)
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')
for old_price in soup.find_all("small", class_ = "product-views-price-old"):
print(old_price.get_text(strip=True).replace('Was: ',''))
driver.quit()
输出
£2.20
£18.61
£27.00
£38.39
£38.39
£20.65
£1.30
£67.99
£20.65
£1.30
£54.95
£30.99
推荐阅读
- vim - Vim ctrlp 仅适用于 git repo
- ios - 如果通过 Xcode 安装 iOS 应用程序运行良好,但通过 TestFlight 安装时在一个特定的视图控制器上崩溃
- python - IPython %run 忽略打印命令
- r - 带有 expss 包的复杂表
- discord.js - Discord.js Foreach 循环添加/删除角色
- maven - Azure Java SDK - 如何/使用哪一个?
- ios - 使用 iPad 多任务实现 Admob
- javascript - 使用 If 语句检查值的有效方法未在 Javascript 或 JQuery 中使用
- spring - SpringBootTest.WebEnvironment.RANDOM_PORT在测试时如何访问local.server.port
- server - 如何限制未登录用户