【发布时间】:2018-06-07 11:29:36
【问题描述】:
我对 Python 中的网络抓取还很陌生;在阅读了有关该主题的大部分在线教程后,我决定试一试。我终于让一个站点正常工作,但输出格式不正确。
import requests
import bs4
from bs4 import BeautifulSoup
import pandas as pd
import time
page = requests.get("https://leeweebrothers.com/our-food/lunch-boxes/#")
soup = BeautifulSoup(page.text, "html.parser")
for div in soup.find_all('h2'): #prints the name of the food"
print(div.text)
for a in soup.find_all('span', {'class' : 'amount'}): #prints price of the food
print(a.text)
输出
我希望将食物的名称与食物的相应价格并排打印,并用“-”连接...不胜感激,谢谢!
编辑:在下面的@Reblochon Masque cmets 之后 - 我遇到了另一个问题;正如您所看到的,有 0.00 美元是网站内置购物车的价值,我如何将其排除为异常值并继续向下移动,同时确保价格中的其他商品“向上移动”以对应吃正确的食物?
【问题讨论】:
标签: python web-scraping printing-web-page