我有一个bs4在craigslist上报废了二手车。现在它返回所有帖子,但我试图获取少于$ 2k的帖子。我知道我要么需要嵌套的if语句,要么需要单独的函数。有帮助吗?
# Loop through returned results
for result in results:
# Error handling
try:
# Identify and return title of listing
title = result.find('a', class_="result-title").text
# Identify and return price of listing
price = result.a.span.text
# Identify and return link to listing
link = result.a['href']
# Print results only if title, price, and link are available
if (price and title and link):
print('-------------')
print(title)
print(price)
print(link)
next
except AttributeError as e:
print(e)
答案 0 :(得分:0)
您可以查看是否node_modules/.bin/gulp
,如果使用int(price) >= 2_000
,则跳过打印:
continue