我正在尝试用多个括号刮一个网站。我的计划是有3个变量(oem,model,leadtime)来生成期望的输出。然而,我不知道如何在3个变量中抓取这个网页。
具有3个变量和命令的期望输出:
打印(oem、型号、交付周期)
Audi, A1 Sportback, 27 weeks
Audi, A3 Sportback, 27 weeks
...
Volvo, XC90, 27 weeks
截至目前的代码错误:
AttributeError: 'NavigableString' object has no attribute 'select'
截至目前的代码:
from bs4 import BeautifulSoup
import requests
response = requests.get("https://www.carwow.co.uk/new-car-delivery-times#gref").text
soup = BeautifulSoup(response, 'html.parser')
for tbody in soup.select('tbody'):
for tr in tbody:
oem = tr.select('td > a')[0].get('href').split('/')[3].capitalize()
model = tr.select('td > a')[0].get('href').split('/')[4].capitalize()
lead_time = tr.select('td')[1].getText(strip=True)
print(oem, model, lead_time)
我对Python和美味汤很陌生。
1条答案
按热度按时间ryevplcw1#
尝试:
打印: