我为this网址开发了一个网络爬虫程序,但是遇到了一个问题。在
我所要做的是抓取每一个二手车库存数据列表,如果在“价格”标签中每个数据的第4列有一个“图像”数据(粉红色图像表示“卖完”),我将跳过该列表并继续抓取下一个库存数据。在
(我上面的意思是跳过下面的代码,开始下一轮的“for循环”。“continue”跳过only“if”函数并继续运行以下代码。)
下面是我的代码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])