from urllib import request
from bs4 import BeautifulSoup as bs
import re
url = 'https://search.musinsa.com/ranking/brand'
target = request.urlopen(url)
soup = bs(target, 'html.parser')
brand = soup.select('.brandLogo img')
brandname = []
print('----------------------------------------------------')
for alt in brand[:5] :
#print(alt.get('alt'))
brandname.append(alt.get('alt'))
print(brandname)
print('----------------------------------------------------')
import json
jsonString = json.dumps(brandname, ensure_ascii=False)
print(jsonString)
from flask import Flask
# 웹서버 생성
app = Flask(__name__)
print(app)
print(__name__)
#url
@app.route('/brand')
def brandName():
return jsonString
if __name__ == '__main__':
app.run(debug=True, port=8000)
from urllib import request
from bs4 import BeautifulSoup as bs
import re
url = 'https://search.musinsa.com/ranking/brand'
target = request.urlopen(url)
soup = bs(target, 'html.parser')
brand = soup.select('.brandLogo img')
rankup = soup.select('.rank')
result_list = soup.find_all('span', class_="rank")
brandname = []
brandrank = []
brandrank_data = []
rank_data = []
for span in result_list[:10] :
brandrank_data.append(span.text)
print(brandrank_data)
print('----------------------------시작------------------------')
for alt in brand[:10] :
#print(alt.get('alt'))
brandname.append(alt.get('alt'))
print(brandname)
print(brandname[0])
print('----------------------------------------------------')
for cla in rankup[:10] :
brandrank.append(cla.get('class'))
print(brandrank)
print('----------------------------------------------------')
for i in range(10) :
rank_data.append(
{
'name':brandname[i],
'rank':brandrank_data[i]
}
)
print(rank_data)
print('----------------------------------------------------')
import json
jsonString = json.dumps(rank_data, ensure_ascii=False)
print(jsonString)
from flask import Flask
# 웹서버 생성
app = Flask(__name__)
#print(app)
#print(__name__)
from flask_cors import CORS
CORS(app)
#url
@app.route('/brand')
def brandName():
return jsonString
if __name__ == '__main__':
app.run(debug=True, port=8000)
'python_basic' 카테고리의 다른 글
[파이썬] flask_cors / crossorigin (0) | 2021.03.08 |
---|---|
[파이썬] pymysql : 파이선에서 mysql 사용하기 (0) | 2021.02.09 |
[파이썬] 아톰 한글깨짐 현상 방지 (0) | 2021.02.09 |
[파이썬] flask (0) | 2021.02.09 |
[파이썬] beautifulsoup / flask 설치하기 (0) | 2021.02.09 |
[파이썬] csv 파일쓰기 / 읽기 (0) | 2020.11.30 |
[파이썬] 파일읽기 / 쓰기 (0) | 2020.11.30 |