简体   繁体   中英

Formatting python scrape output in flask

I have just started web scraping. The eventual idea is to display such information from many websites on my web page. My question is where/what should I start to read about formatting the return statement output. The current output is all garbled. I have tried reading up on it however, couldn't make much sense of it. Is there some place where I can read it in the context of displaying this in a nice way on the web page?

BSE Live Jan 03, 16:00 1537.25 1.90 (0.12%) Volume AVERAGE VOLUME 5-Day 467,144 10-Day 575,986 30-Day 455,188 354,087 Prev. Close 1535.35 Open Price 1534.40 1523.40 Today's L/H 1541.30 1081.25 52 Wk L/H 1617.80 1381.85 L/U Price Band 1688.85 Bid Price (Qty.) 0.00 (0) Offer Price (Qty.) 0.00 (0) VWAP 1535.08 Market Depth (03 Jan 2020) BUYSELL QTY PRICE PRICE QTY 500 1535.05 1535.65 33 301 1534.95 1536.60 21 424 1534.85 1536.70 21 510 1534.75 1536.85 23 1044 1534.70 1537.00 632 0 Total Total 0 Market Depth BUY 0 SELL 0 0% 0% NSE Live Jan 03, 15:59 1537.15 1.85 (0.12%) Volume AVERAGE VOLUME 5-Day 8,111,879 10-Day 9,299,481 30-Day 8,175,032 9,593,498 Prev. Close 1535.30 Open Price 1533.00 1523.00 Today's L/H 1541.65 1081.10 52 Wk L/H 1617.55 1381.80 L/U Price Band 1688.80 Bid Price (Qty.) 0.00 (0) Offer Price (Qty.) 1537.15 (5051) VWAP 1532.73 Represents Equity.Intra - day transactions are permissible and normal trading is done in this category Series: EQ

from flask import Flask
from bs4 import BeautifulSoup
import requests

app = Flask(__name__)

@app.route('/')


# driver = webdriver.Chrome(executable_path="C:/Users/Abhi/Downloads/cd79/chromedriver.exe")
def scrape():
    url = "https://www.moneycontrol.com/india/stockpricequote/refineries/relianceindustries/RI"
    r = requests.get(url)
    soup = BeautifulSoup(r.content, 'html.parser')
    for el in soup.find_all('div', class_='bse_nse_livebox'):
        return el.get_text()


if __name__ == '__main__':
    app.run()

The output has got this layout because of the way you are reading the webpage using BeautifulSoup.

You should try to break the contents of the page parsed by BeautifulSoup, getting all the information you need and displaying in the format you expect. You should probably do this in the code, not in the html page.

You could read more about parsing the page in the BeautifulSoup Documentation. https://www.crummy.com/software/BeautifulSoup/bs4/doc/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM