Python
[python] 검색어 확인
닉의네임
2022. 5. 26. 15:05
반응형
금칙어 리스트를 받았다.. 전수 검사를 요구하네..
음.. 로컬에서는 운영계 검색 api. 호출이 불가능 한 상황
프론트에서 검색을 호출하는 api url 을 추출한 후 금칙어 리스트를 순회 하면서 검색결과를 파일에 기록함
# -*- coding: utf-8 -*-
import time
import json
from elasticsearch import Elasticsearch
from elasticsearch.helpers import bulk
import tensorflow_hub as hub
import tensorflow_text
import kss, numpy
import requests
import ssl
import urllib3
from time import sleep
print(ssl.OPENSSL_VERSION)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def csv_data():
f_v = open("stopword_search_result.txt",'w')
count= 0;
with open(CSV_FILE) as data_file:
for line in data_file:
line = line.strip()
lineArray = line.split(',')
sleep(1)
url = "검색 URL&page=1&perPage=10&originalSearchYn=N&searchType=NONE&inputKeyword="+lineArray[1]+"&searchKeyword="+lineArray[1]+"\n"
response = requests.get(url, verify=False)
json_data = json.loads(response.text)
ret = lineArray[1]+" : total count : "+ str(json_data["pagination"]["totalCount"])
if (json_data["pagination"]["totalCount"] > 0) :
print(ret)
sleep(1)
f_v.write(ret)
count += 1
f_v.close()
print("Done.")
##### MAIN SCRIPT #####
if __name__ == '__main__':
CSV_FILE = "./data/products/stopword0525.csv"
csv_data()
print("Done.")
반응형