from flask import Flask,render_template
app = Flask(__name__)
import pandas as pd
import requests
from bs4 import BeautifulSoup
@app.route('/microsoft')
def microsoft():
data=[]
url = "https://en.wikipedia.org/wiki/Microsoft"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table=soup.find('table',{'class':'wikitable float-left'})
rows=table.find_all('tr')
for row in rows:
data.append([cell.text.replace('\n', ' ')for cell in row.find_all(['th', 'td'])])
df = pd.DataFrame(data[1:],columns=data[0])
return render_template('index.html', header="true", table_id="table", tables=[df.to_html(classes='data')], titles=df.columns.values)
@app.route('/oracle')
def oracle():
data=[]
url="https://en.wikipedia.org/wiki/Oracle_Corporation"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table=soup.find('table',{'class':'wikitable float-left'})
rows=table.find_all('tr')
for row in rows:
data.append([cell.text.replace('\n', ' ')for cell in row.find_all(['th', 'td'])])
df = pd.DataFrame(data[1:],columns=data[0])
return render_template('index.html', header="true", table_id="table", tables=[df.to_html(classes='data')], titles=df.columns.values)
@app.route('/accenture')
def accenture():
data=[]
url="https://en.wikipedia.org/wiki/Accenture"
page = requests.get(url)
soup = BeautifulSoup(page.content, 'html.parser')
table=soup.find('table',{'class':'wikitable float-left plainrowheaders'})
rows=table.find_all('tr')
for row in rows:
data.append([cell.text.replace('\n', ' ')for cell in row.find_all(['th', 'td'])])
df = pd.DataFrame(data[1:],columns=data[0])
return render_template('index.html', header="true", table_id="table", tables=[df.to_html(classes='data')], titles=df.columns.values)
if __name__ == '__main__':
app.run(debug=True)
how to show all scraped wiki tables in single page and scrolling down method or line by line using python flask?
now i get answer only this method http://127.0.0.1:5000/oracle or http://127.0.0.1:5000/accenture or http://127.0.0.1:5000/ibm but i want to show http://127.0.0.1:5000 just click the link, show the all tables.
Aucun commentaire:
Enregistrer un commentaire