我已经开发了一个网址为this的web-crawler,刚刚出了问题。如何跳过一轮“for循环”,并在满足特定的“if”条件时继续下一轮?
我试图做的是抓取每个二手车库存数据列表,如果在每个数据的第四列有一个“图像”数据(粉红色图像表示“售罄”)在“价格“标签,我将跳过该列表并继续抓取下一个股票数据。
(我上面的意思是跳过整个下面的代码,并开始下一轮的“for循环”。“继续”跳过唯一的“如果”功能,并保持运行下面的代码。)
以下是我的代码
from bs4 import BeautifulSoup
import urllib.request
URL=http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I&page=20
res = urllib.request.urlopen(URL)
html = res.read()
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('table', class_='cyber')
# 50 lists per each page
links = []
for p in range(50):
#Car_Price
car_price=table.find_all('td', class_='price')
if car_price[p].find('em').text:
car_price_confirm = car_price[p].find('em').text
elif car_price[p].find('em').find('img'):
pass
carinfo = table.find_all('td', class_='carinfo')
carinfo_title = carinfo[p].find('a', class_='title').text
links.append(carinfo[p].find('a')['href'])
print(p+1, car_price_confirm, link[p])
请您在收到答案后不要完全改变您的问题。如果需要,请提出另一个问题。 –