我要抓取页面,下面是我的代码:
import requests
from bs4 import BeautifulSoup
url = ('https://bama.ir/car/all-brands/all-models/all-trims?hasprice=true&sort=1&page1')
html_content = requests.get(url).text
soup = BeautifulSoup(html_content,'html.parser')
print(url)
names_car = []
prices = []
works = []
for name_car in soup.findAll('h2',{'itemprop':'name'}):
names_car.append(name_car.text.replace('\n',' ').replace('\r',' ').strip())
for price in soup.findAll('p',{'class':'cost'}):
prices.append(price.text.replace('\n',' ').replace('\r',' ').strip())
for work in soup.findAll('p',{'class': 'price milage-text-mobile visible-xs price-milage-mobile'}):
works.append(work.text.replace('\n',' ').replace('\r',' ').strip())
for i in range(0,29):
print({'name':names_car[i],'price':prices[i],'works':works[i]})
问题是:
当我以汽车,价格和工作的名字命名时,很难读懂
此代码仅适用于一页。我如何获得所有页面 和其他问题(当您运行代码时就可以理解)。