from flask import Flask, render_template,request
app = Flask(__name__)
import requests
from bs4 import BeautifulSoup
# 크롤링 라이브러리 import
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
write_wb = Workbook()
write_ws = write_Wb.active
write_ws.cell(1,1,"안녕")
write_wb.save("result.xlsx")
@app.route('/')
def hello():
return render_template("index.html")
@app.route('/result', methods=['POST'])
def result():
if request.method == 'POST':
keyword = request.form['input1']
page = request.form['input2']
# https://search.daum.net/search?nil_suggest=btn&w=news&DA=SBC&cluster=y&q= + keyword
daum_list = []
for i in range(1, int(page) + 1):
req = requests.get("https://search.daum.net/search?nil_suggest=btn&w=news&DA=SBC&cluster=y&q=" + keyword + "&p=" + page)
soup = BeautifulSoup(req.text, 'html.parser')
for i in soup.find_all("a", class_="f_link_b"):
print(i.text)
daum_list.append(i.text)
return render_template("result.html", daum_list = daum_list)
if __name__ == "__main__":
app.run()