-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (35 loc) · 1.6 KB
/
main.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from urllib import request
import requests
from bs4 import BeautifulSoup
import csv
import pandas as pd
from urllib.request import urlopen
import time
from requests.api import head
fields = ['단어', '뜻1', '뜻2', '뜻3','뜻4','뜻5','뜻6'] # csv 파일 제일 상단의 필드
url= "https://dic.daum.net/search.do?q=" #검색할 사이트 url
headers = {'User-Agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"}
xlsx=pd.read_excel("단어장1.xlsx")#convert xlsx to csv, set your xlsx file which you want to fill meanings of word
xlsx.to_csv("converted.csv")
data=list() # list for storage word data
meaning=list()#list for meaning searched from web
f=open("converted.csv",'r')
rea=csv.reader(f)
for row in rea: #load and save data to list 'data'
data.append(row[1]) # change number in '[]' if you want to read other collunm
f.close()
meaning=[] #2D list for saving means for word
f=open("converted.csv",'w',newline='') #set your csv file location
write=csv.writer(f)
write.writerow(fields) #write fields
for i in range(0,len(data)): ##load data from web and save data to 2D list
response = requests.get(url+data[i],headers=headers)
readed_web = BeautifulSoup(response.text,'html.parser')
time.sleep(0.5)
line=[]
line.append(data[i])
for p in readed_web.select("div.cleanword_type ul.list_search span.txt_search"):
line.append(p.get_text())
print(p.get_text())
meaning.append(line)
write.writerows(meaning) #write meaning to csv file