Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

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 flask web page?

Quote: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


Code
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()
It's how you're retrieving the contents of the website with BeautifulSoup. I would look this over: https://www.crummy.com/software/BeautifulSoup/bs4/doc/
[Image: ZEve4.png]
(Jan 3, 2020 09:29 AM)lnvisible Wrote:  It's how you're retrieving the contents of the website with BeautifulSoup. I would look this over: https://www.crummy.com/software/BeautifulSoup/bs4/doc/

I have also made a thread on this if OP wants more help: https://hackforums.net/showthread.php?tid=5954455
(Jan 3, 2020 12:09 PM)AeroBlue Wrote:  I have also made a thread on this if OP wants more help: https://hackforums.net/showthread.php?tid=5954455

Hey ..Thanks for the link. I'd just like t say that..finding the elements isn't an issue..neither is outputting them on the console as text. I was trying to find a way where the output could be formatted for fonts, size. color etc when placed inside a flask app...so It kind of displays the result on the flask web page with formatting..can you point me somewhere to read up on that.
(Jan 4, 2020 01:52 AM)roosiinfidel09 Wrote:  Hey ..Thanks for the link. I'd just like t say that..finding the elements isn't an issue..neither is outputting them on the console as text. I was trying to find a way where the output could be formatted for fonts, size. color etc when placed inside a flask app...so It kind of displays the result on the flask web page with formatting..can you point me somewhere to read up on that.

I don't really know anything about flask, but wouldn't that kinda thing just be done in CSS?
Maybe this will help https://realpython.com/flask-by-example-...soup-nltk/
[Image: 0DvFxnA.gif]
Donate: 3ABKRghau93ziRaDfVwiiwtjky3i1gLrKn
(Jan 4, 2020 04:52 AM)lockhead Wrote:  I don't really know anything about flask, but wouldn't that kinda thing just be done in CSS?
Maybe this will help https://realpython.com/flask-by-example-...soup-nltk/

The problem was the return statement. I didn't know how to format it. The text itself is of course will be handled in CSS and HTML. I am still having trouble with getting to display elements as I want them...but will work on it.
Use templates:
https://www.youtube.com/watch?v=xh3mFxbnc4o
https://realpython.com/primer-on-jinja-templating/
https://flask.palletsprojects.com/en/1.1...templates/
https://blog.miguelgrinberg.com/post/the...-templates
(Jan 11, 2020 06:26 AM)michalmonday Wrote:  Use templates:
https://www.youtube.com/watch?v=xh3mFxbnc4o
https://realpython.com/primer-on-jinja-templating/
https://flask.palletsprojects.com/en/1.1...templates/
https://blog.miguelgrinberg.com/post/the...-templates

Thanks Man!..Exactly what I needed.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 632 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[.NET] by WK8YOUUUSep 24, 2022 04:23 PM 4 206 Sep 24, 2022 04:23 PM
Last Post: BinaryFox
[Python] by еlixirAug 7, 2022 11:43 AM 3 202 Aug 7, 2022 11:43 AM
Last Post: Pat13nt_Zer0