在Flask中格式化Python爬取的输出。

huangapple go评论79阅读模式
英文:

Formatting python scrape output in flask

问题

我刚刚开始进行网页抓取。最终的想法是在我的网页上显示来自许多网站的这种信息。我的问题是在哪里/从哪里开始阅读有关格式化返回语句输出的信息。当前的输出都是乱码。我尝试过阅读相关内容,但无法理解太多。是否有一些地方我可以在网页上以良好的方式显示这些内容的上下文中阅读它?

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

英文:

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()

答案1

得分: 1

输出的布局是由于您使用BeautifulSoup读取网页的方式而产生的。

您应该尝试分解BeautifulSoup解析的页面内容,获取所有您需要的信息,并以您期望的格式显示。您可能应该在代码中完成这个操作,而不是在HTML页面中进行。

您可以在BeautifulSoup文档中了解更多关于解析页面的信息。链接:https://www.crummy.com/software/BeautifulSoup/bs4/doc/

英文:

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/

huangapple
  • 本文由 发表于 2020年1月3日 23:11:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/59580960.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定