2
私は3つの機能を持つプログラムを持っています。各機能は、別のWebページからデータをスクラップし、リストに保存してリストを印刷します。フラスコ:1ページ、3機能 - ウェブページに印刷する機能は1つしかありません
私はこれをTerminalで実行しています。
これらのリストを1つのWebページに印刷したいと考えています。
印刷する機能は1つではありますが、複数の機能をフラスコに入れる方法はわかりません。
は、相続人何作品:
の.pyファイル
from flask import Flask, render_template
import bs4 as bs
import urllib.request
app = Flask(__name__)
@app.route('/')
def chinaAds():
sauce = urllib.request.urlopen('http://www.eslcafe.com/jobs/china/').read()
soup = bs.BeautifulSoup(sauce, 'html.parser')
dl = soup.dl
chinaAds = []
china = []
for words in dl.find_all('a'):
links = words.get('href')
link_text = words.text
if ('university' in link_text.lower()) or ('universities' in link_text.lower()) or ('college' in link_text.lower()) or ('colleges' in link_text.lower()):
chinaAds.append([links, link_text])
for ad in chinaAds:
china.append(tuple(ad))
return render_template("eslJobs.html", china=china)
これは私が私の.htmlファイルに印刷する方法です
<ul class="list-group col-md-4" style="padding-left: 18px;">
{% for href, caption in china %}
<li class="list-group-item"><a href="{{ href }}">{{ caption }}</a></li>
{% endfor %}
</ul>
私は追加したい、私はの.pyファイルに追加するスタッフ
二つの機能は、単に異なる変数で最初と同じであり、彼らは私が印刷される別のウェブページから
def koreaJobs():
sauce = urllib.request.urlopen('http://www.eslcafe.com/jobs/korea/').read()
soup = bs.BeautifulSoup(sauce, 'html.parser')
dl = soup.dl
koreaAds = []
korea []
for words in dl.find_all('a'):
links = words.get('href')
link_text = words.text
if ('university' in link_text.lower()) or ('universities' in link_text.lower()) or ('college' in link_text.lower()) or ('colleges' in link_text.lower()):
koreaAds.append([links, link_text])
for ad in koreaAds:
korea.append(tuple(ad))
return render_template("eslJobs.html", korea=korea)
def intlJobs():
sauce = urllib.request.urlopen('http://www.eslcafe.com/joblist/').read()
soup = bs.BeautifulSoup(sauce, 'html.parser')
dl = soup.dl
intlAds = []
intl = []
for words in dl.find_all('a'):
links = words.get('href')
link_text = words.text
if ('university' in link_text.lower()) or ('universities' in link_text.lower()) or ('college' in link_text.lower()) or ('colleges' in link_text.lower()):
intlAds.append([links, link_text])
for ad in intlAds:
intl.append(tuple(ad))
return render_template("eslJobs.html", intl=intl)
をこすり私の.htmlのページに2つの新しいリストでは、これらの関数からのデータ
感謝。私はあなたの提案からうまく動作するようにしました。戻り値は、関数を変数に置き、render_templateでそれらを呼び出します。乾杯。 – nasan