일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- grafana-loki
- Octavia
- KVM
- libvirt
- cloud-init
- Kubeflow
- ubuntu
- HTML
- i3
- ceph
- ceph-ansible
- kolla-ansible
- nfs-provisioner
- golang
- Docker
- port open
- pacman
- yum
- awx
- Ansible
- terraform
- Arch
- OpenStack
- archlinux
- cephadm
- k8s
- Linux
- kolla
- repository
- Kubernetes
Archives
- Today
- Total
YJWANG
[Python] 부동산 크롤러-2 본문
크롤러-1 에서 가져온 dict를 flask_table을 이용해 html table로 변형하는 코드이다.
import requests, json
from flask_table import Table, Col
class ItemTable(Table):
classes = ['table', 'table-striped', 'table-bordered', 'table-condensed']
articleName = Col('단지')
buildingName = Col('동')
tradeTypeName = Col('매물 종류')
dealOrWarrantPrc = Col('금액')
floorInfo = Col('층')
area2 = Col('평수')
articleConfirmYmd = Col('매물 일자')
articleFeatureDesc = Col('설명')
tagList = Col('태그')
cpPcArticleUrl = Col('링크')
#representativeImgUrl = Col('이미지 링크')
# header 담아서 url에 get 요청 진행 후
# json을 dict 형태로 변환해서 저장
url = 'https://new.land.naver.com/api/articles/complex/2588?realEstateType=APT%3AABYG%3AJGC&tradeType=B1&tag=%3A%3A%3A%3A%3A%3A%3A%3A&rentPriceMin=0&rentPriceMax=900000000&priceMin=0&priceMax=33000&areaMin=0&areaMax=900000000&oldBuildYears&recentlyBuildYears&minHouseHoldCount&maxHouseHoldCount&showArticle=false&sameAddressGroup=true&minMaintenanceCost&maxMaintenanceCost&priceType=RETAIL&directions=&page=1&complexNo=2588&buildingNos=&areaNos=&type=list&order=rank'
headers = {'User-Agent' : 'yjwang'}
resp = requests.get(url, headers = headers).json()
try:
table = ItemTable(resp['articleList'])
except:
pass
print(table.__html__())
# html 결과를 아래와 같이 파일로 저장
f = open('./test.html', 'w')
f.write(table.__html__())
f.close()

반응형