작성
·
331
0
from flask import Flask, render_template, request
app = Flask(__name__)
# 크롤링 라이브러리 import
import requests
from bs4 import BeautifulSoup
from openpyxl import Workbook
write_wb = Workbook()
write_ws = write_wb.active
@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)
for i in range(1, len(daum_list) + 1):
write_ws.cell(i, 1, daum_list[i-1])
write_wb.save("result.xlsx")
return render_template("result.html", daum_list = daum_list)
if __name__ == "__main__":
app.run()
왜 저만 안되는 건지 ? ㅠㅠ