diff --git a/main.py b/main.py index fe397fc..0fff00a 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,8 @@ -from scrap.local_councils.gyeongsangbuk import scrap_andong, scrap_pohang, scrap_gyeongju +from scrap.local_councils.gyeongsangbuk import ( + scrap_andong, + scrap_pohang, + scrap_gyeongju, +) -if __name__ == '__main__': - print(scrap_gyeongju()) \ No newline at end of file +if __name__ == "__main__": + print(scrap_gyeongju()) diff --git a/scrap/local_councils/gyeongsangbuk/__init__.py b/scrap/local_councils/gyeongsangbuk/__init__.py index 2ae24c7..9204778 100644 --- a/scrap/local_councils/gyeongsangbuk/__init__.py +++ b/scrap/local_councils/gyeongsangbuk/__init__.py @@ -7,4 +7,4 @@ from .gimcheon import scrap_gimcheon from .sangju import scrap_sangju from .moongyeong import scrap_moongyeong -from .yaecheon import scrap_yaecheon \ No newline at end of file +from .yaecheon import scrap_yaecheon diff --git a/scrap/local_councils/gyeongsangbuk/andong.py b/scrap/local_councils/gyeongsangbuk/andong.py index f9f7f23..3a1601d 100644 --- a/scrap/local_councils/gyeongsangbuk/andong.py +++ b/scrap/local_councils/gyeongsangbuk/andong.py @@ -6,17 +6,18 @@ import re -def scrap_andong(url = 'https://council.andong.go.kr/kr/member/name.do') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_andong(url="https://council.andong.go.kr/kr/member/name.do") -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_='profile'): + for profile in soup.find_all("div", class_="profile"): name_tag = profile.find("em", class_="name") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +30,9 @@ def scrap_andong(url = 'https://council.andong.go.kr/kr/member/name.do') -> Scra return ScrapResult( council_id="andong", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_andong()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_andong()) diff --git a/scrap/local_councils/gyeongsangbuk/gimcheon.py b/scrap/local_councils/gyeongsangbuk/gimcheon.py index 4f26f50..13a0cc1 100644 --- a/scrap/local_councils/gyeongsangbuk/gimcheon.py +++ b/scrap/local_councils/gyeongsangbuk/gimcheon.py @@ -5,18 +5,19 @@ from scrap.utils.requests import get_soup import re -def scrap_gimcheon(url = 'https://council.gc.go.kr/kr/member/active.do') -> ScrapResult: - '''김천시 페이지에서 의원 상세약력 스크랩 + +def scrap_gimcheon(url="https://council.gc.go.kr/kr/member/active.do") -> ScrapResult: + """김천시 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='memberList')[0] + mlist = soup.find_all("ul", class_="memberList")[0] - for profile in mlist.find_all('li', recursive=False): + for profile in mlist.find_all("li", recursive=False): name_tag = profile.find("h4") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +30,9 @@ def scrap_gimcheon(url = 'https://council.gc.go.kr/kr/member/active.do') -> Scra return ScrapResult( council_id="gimcheon", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_gimcheon()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_gimcheon()) diff --git a/scrap/local_councils/gyeongsangbuk/gumi.py b/scrap/local_councils/gyeongsangbuk/gumi.py index d20f66d..1275ae7 100644 --- a/scrap/local_councils/gyeongsangbuk/gumi.py +++ b/scrap/local_councils/gyeongsangbuk/gumi.py @@ -5,18 +5,21 @@ from scrap.utils.requests import get_soup import re -def scrap_gumi(url = 'https://gumici.or.kr/content/member/memberName.html') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_gumi( + url="https://gumici.or.kr/content/member/memberName.html", +) -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='mlist')[0] + mlist = soup.find_all("ul", class_="mlist")[0] - for profile in mlist.find_all('li'): + for profile in mlist.find_all("li"): name_tag = profile.find("dd", class_="name") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -27,10 +30,9 @@ def scrap_gumi(url = 'https://gumici.or.kr/content/member/memberName.html') -> S councilors.append(Councilor(name=name, party=party)) return ScrapResult( - council_id="gumi", - council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + council_id="gumi", council_type=CouncilType.LOCAL_COUNCIL, councilors=councilors ) -if __name__ == '__main__': - print(scrap_gumi()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_gumi()) diff --git a/scrap/local_councils/gyeongsangbuk/gyeongju.py b/scrap/local_councils/gyeongsangbuk/gyeongju.py index c8c4dc2..b98b606 100644 --- a/scrap/local_councils/gyeongsangbuk/gyeongju.py +++ b/scrap/local_councils/gyeongsangbuk/gyeongju.py @@ -6,32 +6,36 @@ import re import requests -def scrap_gyeongju(url = 'https://council.gyeongju.go.kr/kr/member/name.do') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_gyeongju( + url="https://council.gyeongju.go.kr/kr/member/name.do", +) -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_="profile"): + for profile in soup.find_all("div", class_="profile"): data_uid = profile.find("a", class_="btn_profile")["data-uid"] - + if data_uid: url = f"https://council.gyeongju.go.kr/common/async/member/{data_uid}.do" result = requests.get(url).json() - name = result['name'] if result['name'] else "이름 정보 없음" - party = result['party_nm'] if result['party_nm'] else "정당 정보 없음" + name = result["name"] if result["name"] else "이름 정보 없음" + party = result["party_nm"] if result["party_nm"] else "정당 정보 없음" councilors.append(Councilor(name=name, party=party)) return ScrapResult( council_id="gyeongju", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_gyeongju()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_gyeongju()) diff --git a/scrap/local_councils/gyeongsangbuk/moongyeong.py b/scrap/local_councils/gyeongsangbuk/moongyeong.py index a231b05..8c5b4f4 100644 --- a/scrap/local_councils/gyeongsangbuk/moongyeong.py +++ b/scrap/local_councils/gyeongsangbuk/moongyeong.py @@ -6,32 +6,34 @@ import re import requests -def scrap_moongyeong(url = 'https://council.gbmg.go.kr/kr/member/name.do') -> ScrapResult: - '''문경시 페이지에서 의원 상세약력 스크랩 + +def scrap_moongyeong(url="https://council.gbmg.go.kr/kr/member/name.do") -> ScrapResult: + """문경시 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_="profile"): + for profile in soup.find_all("div", class_="profile"): data_uid = profile.find("a", class_="btn_profile")["data-uid"] - + if data_uid: url = f"https://council.gbmg.go.kr/common/async/member/{data_uid}.do" result = requests.get(url).json() - name = result['name'] if result['name'] else "이름 정보 없음" - party = result['party_nm'] if result['party_nm'] else "정당 정보 없음" + name = result["name"] if result["name"] else "이름 정보 없음" + party = result["party_nm"] if result["party_nm"] else "정당 정보 없음" councilors.append(Councilor(name=name, party=party)) return ScrapResult( council_id="moongyeong", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_moongyeong()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_moongyeong()) diff --git a/scrap/local_councils/gyeongsangbuk/pohang.py b/scrap/local_councils/gyeongsangbuk/pohang.py index 699df22..5b052d0 100644 --- a/scrap/local_councils/gyeongsangbuk/pohang.py +++ b/scrap/local_councils/gyeongsangbuk/pohang.py @@ -5,18 +5,21 @@ from scrap.utils.requests import get_soup import re -def scrap_pohang(url = 'https://council.pohang.go.kr/content/member/memberName.html') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_pohang( + url="https://council.pohang.go.kr/content/member/memberName.html", +) -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='mlist')[0] + mlist = soup.find_all("ul", class_="mlist")[0] - for profile in mlist.find_all('li'): + for profile in mlist.find_all("li"): name_tag = profile.find("dd", class_="name") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +32,9 @@ def scrap_pohang(url = 'https://council.pohang.go.kr/content/member/memberName.h return ScrapResult( council_id="pohang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_pohang()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_pohang()) diff --git a/scrap/local_councils/gyeongsangbuk/sangju.py b/scrap/local_councils/gyeongsangbuk/sangju.py index 6d0326a..531ba5c 100644 --- a/scrap/local_councils/gyeongsangbuk/sangju.py +++ b/scrap/local_councils/gyeongsangbuk/sangju.py @@ -6,17 +6,20 @@ import re -def scrap_sangju(url = 'https://www.sangjucouncil.go.kr/kr/member/name.do') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_sangju( + url="https://www.sangjucouncil.go.kr/kr/member/name.do", +) -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_='profile'): + for profile in soup.find_all("div", class_="profile"): name_tag = profile.find("div", class_="name").find("strong") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +32,9 @@ def scrap_sangju(url = 'https://www.sangjucouncil.go.kr/kr/member/name.do') -> S return ScrapResult( council_id="sangju", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_sangju()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_sangju()) diff --git a/scrap/local_councils/gyeongsangbuk/yaecheon.py b/scrap/local_councils/gyeongsangbuk/yaecheon.py index 8527ec0..3e31bee 100644 --- a/scrap/local_councils/gyeongsangbuk/yaecheon.py +++ b/scrap/local_councils/gyeongsangbuk/yaecheon.py @@ -7,32 +7,34 @@ import re -def scrap_yaecheon(url = 'https://www.ycgcl.kr/kr/member/name.do') -> ScrapResult: - '''예천시 페이지에서 의원 상세약력 스크랩 + +def scrap_yaecheon(url="https://www.ycgcl.kr/kr/member/name.do") -> ScrapResult: + """예천시 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_="profile"): + for profile in soup.find_all("div", class_="profile"): data_uid = profile.find("a", class_="btn_profile")["data-uid"] - + if data_uid: url = f"https://www.ycgcl.kr/common/async/member/{data_uid}.do" result = requests.get(url).json() - name = result['name'] if result['name'] else "이름 정보 없음" - party = result['party_nm'] if result['party_nm'] else "정당 정보 없음" + name = result["name"] if result["name"] else "이름 정보 없음" + party = result["party_nm"] if result["party_nm"] else "정당 정보 없음" councilors.append(Councilor(name=name, party=party)) return ScrapResult( council_id="yaecheon", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_yaecheon()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_yaecheon()) diff --git a/scrap/local_councils/gyeongsangnam/changnyeong.py b/scrap/local_councils/gyeongsangnam/changnyeong.py index d7e1761..8f09573 100644 --- a/scrap/local_councils/gyeongsangnam/changnyeong.py +++ b/scrap/local_councils/gyeongsangnam/changnyeong.py @@ -5,21 +5,26 @@ from scrap.utils.requests import get_soup import requests -def scrap_changnyeong(url = 'https://www.cngc.go.kr/kr/member/active') -> ScrapResult: - '''창녕군 페이지에서 의원 상세약력 스크랩 + +def scrap_changnyeong(url="https://www.cngc.go.kr/kr/member/active") -> ScrapResult: + """창녕군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('div', class_='card_area') + mlist = soup.find_all("div", class_="card_area") for profile in mlist: - info = profile.find_all('li') + info = profile.find_all("li") if info: - name = profile.find("dt").get_text(strip=True).split("(")[0] if profile.find("dt").get_text(strip=True) else "이름 정보 없음" + name = ( + profile.find("dt").get_text(strip=True).split("(")[0] + if profile.find("dt").get_text(strip=True) + else "이름 정보 없음" + ) party = "정당 정보 없음" party_dd = info[2].get_text(strip=True).replace("정 당 :", "") @@ -30,8 +35,9 @@ def scrap_changnyeong(url = 'https://www.cngc.go.kr/kr/member/active') -> ScrapR return ScrapResult( council_id="geoje", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_changnyeong()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_changnyeong()) diff --git a/scrap/local_councils/gyeongsangnam/changwon.py b/scrap/local_councils/gyeongsangnam/changwon.py index 4d6f812..5273341 100644 --- a/scrap/local_councils/gyeongsangnam/changwon.py +++ b/scrap/local_councils/gyeongsangnam/changwon.py @@ -5,18 +5,21 @@ from scrap.utils.requests import get_soup import re -def scrap_changwon(url = 'https://gumici.or.kr/content/member/memberName.html') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_changwon( + url="https://gumici.or.kr/content/member/memberName.html", +) -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='mlist')[0] + mlist = soup.find_all("ul", class_="mlist")[0] - for profile in mlist.find_all('li'): + for profile in mlist.find_all("li"): name_tag = profile.find("dd", class_="name") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +32,9 @@ def scrap_changwon(url = 'https://gumici.or.kr/content/member/memberName.html') return ScrapResult( council_id="changwon", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_changwon()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_changwon()) diff --git a/scrap/local_councils/gyeongsangnam/geoje.py b/scrap/local_councils/gyeongsangnam/geoje.py index e1cd85e..d12f06c 100644 --- a/scrap/local_councils/gyeongsangnam/geoje.py +++ b/scrap/local_councils/gyeongsangnam/geoje.py @@ -5,21 +5,28 @@ from scrap.utils.requests import get_soup import requests -def scrap_geoje(url = 'https://www.gjcl.go.kr/source/korean/member/active.html') -> ScrapResult: - '''거제시 페이지에서 의원 상세약력 스크랩 + +def scrap_geoje( + url="https://www.gjcl.go.kr/source/korean/member/active.html", +) -> ScrapResult: + """거제시 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('dl') + mlist = soup.find_all("dl") for profile in mlist: - info = profile.find_all('li') + info = profile.find_all("li") if info: - name = profile.find("dt").get_text(strip=True) if profile.find("dt").get_text(strip=True) else "이름 정보 없음" + name = ( + profile.find("dt").get_text(strip=True) + if profile.find("dt").get_text(strip=True) + else "이름 정보 없음" + ) party = "정당 정보 없음" party_dd = info[2].get_text(strip=True).replace("정당 :", "") @@ -30,8 +37,9 @@ def scrap_geoje(url = 'https://www.gjcl.go.kr/source/korean/member/active.html') return ScrapResult( council_id="geoje", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_geoje()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_geoje()) diff --git a/scrap/local_councils/gyeongsangnam/gimhae.py b/scrap/local_councils/gyeongsangnam/gimhae.py index d14294d..74d2b27 100644 --- a/scrap/local_councils/gyeongsangnam/gimhae.py +++ b/scrap/local_councils/gyeongsangnam/gimhae.py @@ -5,21 +5,26 @@ from scrap.utils.requests import get_soup import requests -def scrap_gimhae(url = 'https://council.gimhae.go.kr/kr/member/active') -> ScrapResult: - '''창녕군 페이지에서 의원 상세약력 스크랩 + +def scrap_gimhae(url="https://council.gimhae.go.kr/kr/member/active") -> ScrapResult: + """창녕군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('div', class_='card_area') + mlist = soup.find_all("div", class_="card_area") for profile in mlist: - info = profile.find_all('li') + info = profile.find_all("li") if info: - name = profile.find("dt").get_text(strip=True).split("(")[0] if profile.find("dt").get_text(strip=True) else "이름 정보 없음" + name = ( + profile.find("dt").get_text(strip=True).split("(")[0] + if profile.find("dt").get_text(strip=True) + else "이름 정보 없음" + ) party = "정당 정보 없음" party_dd = info[2].get_text(strip=True).replace("정 당 :", "") @@ -30,8 +35,9 @@ def scrap_gimhae(url = 'https://council.gimhae.go.kr/kr/member/active') -> Scrap return ScrapResult( council_id="gimhae", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_gimhae()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_gimhae()) diff --git a/scrap/local_councils/gyeongsangnam/goseong.py b/scrap/local_councils/gyeongsangnam/goseong.py index 4b2081b..1eff641 100644 --- a/scrap/local_councils/gyeongsangnam/goseong.py +++ b/scrap/local_councils/gyeongsangnam/goseong.py @@ -3,7 +3,9 @@ from scrap.utils.requests import get_soup -def scrap_goseong(url="https://council.goseong.go.kr/kr/member/active.do") -> ScrapResult: +def scrap_goseong( + url="https://council.goseong.go.kr/kr/member/active.do", +) -> ScrapResult: """ Scrap councilors’ details from Yongsan-gu District Council of Seoul page. diff --git a/scrap/local_councils/gyeongsangnam/hanam.py b/scrap/local_councils/gyeongsangnam/hanam.py index 5e7be5a..238881b 100644 --- a/scrap/local_councils/gyeongsangnam/hanam.py +++ b/scrap/local_councils/gyeongsangnam/hanam.py @@ -5,20 +5,25 @@ from scrap.utils.requests import get_soup import requests -def scrap_hanam(url = 'https://www.haman.go.kr/04646/04669.web') -> ScrapResult: - '''합천군 페이지에서 의원 상세약력 스크랩 + +def scrap_hanam(url="https://www.haman.go.kr/04646/04669.web") -> ScrapResult: + """합천군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('div', class_='column') + mlist = soup.find_all("div", class_="column") for profile in mlist: - name = profile.find("h2").get_text(strip=True).split("\n")[0] if profile.find("h2").get_text(strip=True) else "이름 정보 없음" - info = profile.find_all('li') + name = ( + profile.find("h2").get_text(strip=True).split("\n")[0] + if profile.find("h2").get_text(strip=True) + else "이름 정보 없음" + ) + info = profile.find_all("li") if info: party = "정당 정보 없음" party_dd = info[2].get_text(strip=True).replace("정당", "") @@ -29,8 +34,9 @@ def scrap_hanam(url = 'https://www.haman.go.kr/04646/04669.web') -> ScrapResult: return ScrapResult( council_id="hanam", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_hanam()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_hanam()) diff --git a/scrap/local_councils/gyeongsangnam/hapchun.py b/scrap/local_councils/gyeongsangnam/hapchun.py index 9af2186..47cb577 100644 --- a/scrap/local_councils/gyeongsangnam/hapchun.py +++ b/scrap/local_councils/gyeongsangnam/hapchun.py @@ -5,21 +5,28 @@ from scrap.utils.requests import get_soup import requests -def scrap_hapchun(url = 'https://www.hccl.go.kr/source/korean/member/active.jsp') -> ScrapResult: - '''합천군 페이지에서 의원 상세약력 스크랩 + +def scrap_hapchun( + url="https://www.hccl.go.kr/source/korean/member/active.jsp", +) -> ScrapResult: + """합천군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('dl', class_='member') + mlist = soup.find_all("dl", class_="member") for profile in mlist: - info = profile.find_all('li') + info = profile.find_all("li") if info: - name = info[0].get_text(strip=True) if info[0].get_text(strip=True) else "이름 정보 없음" + name = ( + info[0].get_text(strip=True) + if info[0].get_text(strip=True) + else "이름 정보 없음" + ) party = "정당 정보 없음" party_dd = info[3].get_text(strip=True).replace("소속정당 : ", "") @@ -30,8 +37,9 @@ def scrap_hapchun(url = 'https://www.hccl.go.kr/source/korean/member/active.jsp' return ScrapResult( council_id="hapchun", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_hapchun()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_hapchun()) diff --git a/scrap/local_councils/gyeongsangnam/jinju.py b/scrap/local_councils/gyeongsangnam/jinju.py index c55f0f9..0b1d6fe 100644 --- a/scrap/local_councils/gyeongsangnam/jinju.py +++ b/scrap/local_councils/gyeongsangnam/jinju.py @@ -6,17 +6,18 @@ import re -def scrap_jinju(url = 'https://www.jinjucl.com/kr/member/name.do') -> ScrapResult: - '''대전시 동구 페이지에서 의원 상세약력 스크랩 + +def scrap_jinju(url="https://www.jinjucl.com/kr/member/name.do") -> ScrapResult: + """대전시 동구 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_='profile'): + for profile in soup.find_all("div", class_="profile"): name_tag = profile.find("div", class_="name").find("strong") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +30,9 @@ def scrap_jinju(url = 'https://www.jinjucl.com/kr/member/name.do') -> ScrapResul return ScrapResult( council_id="jinju", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_jinju()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_jinju()) diff --git a/scrap/local_councils/gyeongsangnam/miryang.py b/scrap/local_councils/gyeongsangnam/miryang.py index a59d5f8..d61211f 100644 --- a/scrap/local_councils/gyeongsangnam/miryang.py +++ b/scrap/local_councils/gyeongsangnam/miryang.py @@ -4,23 +4,29 @@ from scrap.utils.types import CouncilType, Councilor, ScrapResult from scrap.utils.requests import get_soup -def scrap_miryang(url = 'https://council.miryang.go.kr/web/EgovCouncilManList.do?menuNo=14010100') -> ScrapResult: - '''밀양시 의회 페이지에서 의원 상세약력 스크랩 + +def scrap_miryang( + url="https://council.miryang.go.kr/web/EgovCouncilManList.do?menuNo=14010100", +) -> ScrapResult: + """밀양시 의회 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - - for profile in soup.find_all('div', class_="council_box"): - name_tag = profile.find("span", string="이름").find_next("span").get_text(strip=True) + for profile in soup.find_all("div", class_="council_box"): + name_tag = ( + profile.find("span", string="이름").find_next("span").get_text(strip=True) + ) name = name_tag if name_tag else "이름 정보 없음" party = "정당 정보 없음" - party_info = profile.find("span", string="소속정당").find_next("span").get_text(strip=True) + party_info = ( + profile.find("span", string="소속정당").find_next("span").get_text(strip=True) + ) if party_info: party = party_info councilors.append(Councilor(name=name, party=party)) @@ -28,8 +34,9 @@ def scrap_miryang(url = 'https://council.miryang.go.kr/web/EgovCouncilManList.do return ScrapResult( council_id="miryang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_miryang()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_miryang()) diff --git a/scrap/local_councils/gyeongsangnam/namhae.py b/scrap/local_councils/gyeongsangnam/namhae.py index 526469b..4755ffa 100644 --- a/scrap/local_councils/gyeongsangnam/namhae.py +++ b/scrap/local_councils/gyeongsangnam/namhae.py @@ -5,16 +5,19 @@ from scrap.utils.requests import get_soup import re -def scrap_namhae(url = 'https://council.namhae.go.kr/source/korean/member/active.html') -> ScrapResult: - '''남해 페이지에서 의원 상세약력 스크랩 + +def scrap_namhae( + url="https://council.namhae.go.kr/source/korean/member/active.html", +) -> ScrapResult: + """남해 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False, encoding="euc-kr") councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_="profile"): + for profile in soup.find_all("div", class_="profile"): name_tag = profile.find("li", class_="name") name = name_tag.get_text(strip=True).split("(")[0] if name_tag else "이름 정보 없음" @@ -27,8 +30,9 @@ def scrap_namhae(url = 'https://council.namhae.go.kr/source/korean/member/active return ScrapResult( council_id="yangsan", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_namhae()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_namhae()) diff --git a/scrap/local_councils/gyeongsangnam/sacheon.py b/scrap/local_councils/gyeongsangnam/sacheon.py index c0807bc..91e8e55 100644 --- a/scrap/local_councils/gyeongsangnam/sacheon.py +++ b/scrap/local_councils/gyeongsangnam/sacheon.py @@ -3,7 +3,9 @@ from scrap.utils.requests import get_soup -def scrap_sacheon(url="https://council.sacheon.go.kr/kr/member/active.do") -> ScrapResult: +def scrap_sacheon( + url="https://council.sacheon.go.kr/kr/member/active.do", +) -> ScrapResult: """ Scrap councilors’ details from Yongsan-gu District Council of Seoul page. diff --git a/scrap/local_councils/gyeongsangnam/sanchung.py b/scrap/local_councils/gyeongsangnam/sanchung.py index deeab16..04b87c8 100644 --- a/scrap/local_councils/gyeongsangnam/sanchung.py +++ b/scrap/local_councils/gyeongsangnam/sanchung.py @@ -5,23 +5,30 @@ from scrap.utils.requests import get_soup import requests -def scrap_sanchung(url = 'https://www.sancheong.go.kr/council/selectPersonalAssembly.do?key=2224&assemCate=8') -> ScrapResult: - '''산청군 페이지에서 의원 상세약력 스크랩 + +def scrap_sanchung( + url="https://www.sancheong.go.kr/council/selectPersonalAssembly.do?key=2224&assemCate=8", +) -> ScrapResult: + """산청군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find('ul', class_='comment_list') - lis = mlist.find_all('li', recursive=False) + mlist = soup.find("ul", class_="comment_list") + lis = mlist.find_all("li", recursive=False) for profile in lis: print(profile) - info = profile.find_all('li') - name = profile.find("span", class_="name").get_text(strip=True) if profile.find("span", class_="name").get_text(strip=True) else "이름 정보 없음" + info = profile.find_all("li") + name = ( + profile.find("span", class_="name").get_text(strip=True) + if profile.find("span", class_="name").get_text(strip=True) + else "이름 정보 없음" + ) party = "정당 정보 없음" - + party_dd = info[3].get_text(strip=True).replace("소속정당", "") if party_dd: party = party_dd @@ -30,8 +37,9 @@ def scrap_sanchung(url = 'https://www.sancheong.go.kr/council/selectPersonalAsse return ScrapResult( council_id="hapchun", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_sanchung()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_sanchung()) diff --git a/scrap/local_councils/gyeongsangnam/uiryeong.py b/scrap/local_councils/gyeongsangnam/uiryeong.py index 71bd42c..5a7d23e 100644 --- a/scrap/local_councils/gyeongsangnam/uiryeong.py +++ b/scrap/local_councils/gyeongsangnam/uiryeong.py @@ -3,7 +3,9 @@ from scrap.utils.requests import get_soup -def scrap_uiryeong(url="https://www.uiryeong.go.kr/board/list.uiryeong?boardId=BBS_0000169&menuCd=DOM_000000502001000000&contentsSid=1040") -> ScrapResult: +def scrap_uiryeong( + url="https://www.uiryeong.go.kr/board/list.uiryeong?boardId=BBS_0000169&menuCd=DOM_000000502001000000&contentsSid=1040", +) -> ScrapResult: """ Scrap councilors’ details from Yongsan-gu District Council of Seoul page. diff --git a/scrap/local_councils/gyeongsangnam/yangsan.py b/scrap/local_councils/gyeongsangnam/yangsan.py index 829d5fa..c5964ab 100644 --- a/scrap/local_councils/gyeongsangnam/yangsan.py +++ b/scrap/local_councils/gyeongsangnam/yangsan.py @@ -5,16 +5,17 @@ from scrap.utils.requests import get_soup import re -def scrap_yangsan(url = 'https://www.yscouncil.go.kr/kr/member/active') -> ScrapResult: - '''양산시 페이지에서 의원 상세약력 스크랩 + +def scrap_yangsan(url="https://www.yscouncil.go.kr/kr/member/active") -> ScrapResult: + """양산시 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - for profile in soup.find_all('div', class_="member"): + for profile in soup.find_all("div", class_="member"): name_tag = profile.find("strong", class_="name") name = name_tag.get_text(strip=True).split("(")[0] if name_tag else "이름 정보 없음" @@ -27,8 +28,9 @@ def scrap_yangsan(url = 'https://www.yscouncil.go.kr/kr/member/active') -> Scrap return ScrapResult( council_id="yangsan", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_yangsan()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_yangsan()) diff --git a/scrap/local_councils/junnam/danyang.py b/scrap/local_councils/junnam/danyang.py index 34e7a38..4377791 100644 --- a/scrap/local_councils/junnam/danyang.py +++ b/scrap/local_councils/junnam/danyang.py @@ -5,20 +5,25 @@ from scrap.utils.requests import get_soup import re -def scrap_damyang(url = 'https://council.gc.go.kr/kr/member/active.do') -> ScrapResult: - '''담양군 페이지에서 의원 상세약력 스크랩 + +def scrap_damyang(url="https://council.gc.go.kr/kr/member/active.do") -> ScrapResult: + """담양군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='memlist')[0] + mlist = soup.find_all("ul", class_="memlist")[0] - for profile in mlist.find_all('li', recursive=False): - info = profile.find('ul', class_='info') - name = info.find("h5").get_text(strip=True) if info.find("h5").get_text(strip=True) else "이름 정보 없음" + for profile in mlist.find_all("li", recursive=False): + info = profile.find("ul", class_="info") + name = ( + info.find("h5").get_text(strip=True) + if info.find("h5").get_text(strip=True) + else "이름 정보 없음" + ) li = info.find("li", class_="item MP") party = "정당 정보 없음" @@ -30,8 +35,9 @@ def scrap_damyang(url = 'https://council.gc.go.kr/kr/member/active.do') -> Scrap return ScrapResult( council_id="damyang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_damyang()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_damyang()) diff --git a/scrap/local_councils/junnam/gangjin.py b/scrap/local_councils/junnam/gangjin.py index b4719f3..b7ff1aa 100644 --- a/scrap/local_councils/junnam/gangjin.py +++ b/scrap/local_councils/junnam/gangjin.py @@ -5,20 +5,25 @@ from scrap.utils.requests import get_soup import re -def scrap_gangjin(url = 'https://www.gangjincl.go.kr/index.do?PID=010') -> ScrapResult: - '''강진군 페이지에서 의원 상세약력 스크랩 + +def scrap_gangjin(url="https://www.gangjincl.go.kr/index.do?PID=010") -> ScrapResult: + """강진군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='memlist')[0] + mlist = soup.find_all("ul", class_="memlist")[0] - for profile in mlist.find_all('li', recursive=False): - info = profile.find('ul', class_='info') - name = info.find("h5").get_text(strip=True) if info.find("h5").get_text(strip=True) else "이름 정보 없음" + for profile in mlist.find_all("li", recursive=False): + info = profile.find("ul", class_="info") + name = ( + info.find("h5").get_text(strip=True) + if info.find("h5").get_text(strip=True) + else "이름 정보 없음" + ) li = info.find_all("li", recursive=False)[6] party = "정당 정보 없음" @@ -30,8 +35,9 @@ def scrap_gangjin(url = 'https://www.gangjincl.go.kr/index.do?PID=010') -> Scrap return ScrapResult( council_id="damyang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_gangjin()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_gangjin()) diff --git a/scrap/local_councils/junnam/goheung.py b/scrap/local_councils/junnam/goheung.py index 4751184..6f19a48 100644 --- a/scrap/local_councils/junnam/goheung.py +++ b/scrap/local_councils/junnam/goheung.py @@ -5,20 +5,25 @@ from scrap.utils.requests import get_soup import re -def scrap_goheung(url = 'https://council.gc.go.kr/kr/member/active.do') -> ScrapResult: - '''고흥군 페이지에서 의원 상세약력 스크랩 + +def scrap_goheung(url="https://council.gc.go.kr/kr/member/active.do") -> ScrapResult: + """고흥군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='memlist')[0] + mlist = soup.find_all("ul", class_="memlist")[0] - for profile in mlist.find_all('li', recursive=False): - info = profile.find('ul', class_='info') - name = info.find("h5").get_text(strip=True) if info.find("h5").get_text(strip=True) else "이름 정보 없음" + for profile in mlist.find_all("li", recursive=False): + info = profile.find("ul", class_="info") + name = ( + info.find("h5").get_text(strip=True) + if info.find("h5").get_text(strip=True) + else "이름 정보 없음" + ) li = info.find("li", class_="item MP") party = "정당 정보 없음" @@ -30,8 +35,9 @@ def scrap_goheung(url = 'https://council.gc.go.kr/kr/member/active.do') -> Scrap return ScrapResult( council_id="damyang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_damyang()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_damyang()) diff --git a/scrap/local_councils/junnam/hamppyeong.py b/scrap/local_councils/junnam/hamppyeong.py index 741ee9d..b8a6241 100644 --- a/scrap/local_councils/junnam/hamppyeong.py +++ b/scrap/local_councils/junnam/hamppyeong.py @@ -5,26 +5,33 @@ from scrap.utils.requests import get_soup import re -def scrap_hamppyeong(url = 'https://www.hpcouncil.go.kr/main/incumbentCouncillor.do?PID=0201&item=01') -> ScrapResult: - '''무안 페이지에서 의원 상세약력 스크랩 + +def scrap_hamppyeong( + url="https://www.hpcouncil.go.kr/main/incumbentCouncillor.do?PID=0201&item=01", +) -> ScrapResult: + """무안 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('div', id='subContent')[0] + mlist = soup.find_all("div", id="subContent")[0] total_div = mlist.find_all("div", class_="infosubcontent") total_div.append(mlist.find_all("div", class_="infosubcontent2")) for profile in total_div: if not profile: continue - info = profile.find('div', class_='infosub_detail') - name = info.find("li", class_="infosubmem_name" ).get_text(strip=False)[:3] if info.find("li", class_="infosubmem_name" ).get_text(strip=True) else "이름 정보 없음" + info = profile.find("div", class_="infosub_detail") + name = ( + info.find("li", class_="infosubmem_name").get_text(strip=False)[:3] + if info.find("li", class_="infosubmem_name").get_text(strip=True) + else "이름 정보 없음" + ) - party_dd = info.find("ul", class_="infosub").find_all('li')[1] + party_dd = info.find("ul", class_="infosub").find_all("li")[1] party = "정당 정보 없음" if party_dd: party = party_dd.get_text(strip=True).replace("소속정당 : ", "") @@ -33,8 +40,9 @@ def scrap_hamppyeong(url = 'https://www.hpcouncil.go.kr/main/incumbentCouncillor return ScrapResult( council_id="yeonggwang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_hamppyeong()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_hamppyeong()) diff --git a/scrap/local_councils/junnam/henam.py b/scrap/local_councils/junnam/henam.py index 27011b1..b344bc7 100644 --- a/scrap/local_councils/junnam/henam.py +++ b/scrap/local_councils/junnam/henam.py @@ -5,18 +5,19 @@ from scrap.utils.requests import get_soup import re -def scrap_henam(url = 'http://council.haenam.go.kr/kr/member/active.do') -> ScrapResult: - '''해남 페이지에서 의원 상세약력 스크랩 + +def scrap_henam(url="http://council.haenam.go.kr/kr/member/active.do") -> ScrapResult: + """해남 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='memberList')[0] + mlist = soup.find_all("ul", class_="memberList")[0] - for profile in mlist.find_all('li', recursive=False): + for profile in mlist.find_all("li", recursive=False): name_tag = profile.find("h4") name = name_tag.get_text(strip=True) if name_tag else "이름 정보 없음" @@ -29,8 +30,9 @@ def scrap_henam(url = 'http://council.haenam.go.kr/kr/member/active.do') -> Scra return ScrapResult( council_id="gimcheon", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_henam()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_henam()) diff --git a/scrap/local_councils/junnam/muan.py b/scrap/local_councils/junnam/muan.py index 9684f4d..cb4f175 100644 --- a/scrap/local_councils/junnam/muan.py +++ b/scrap/local_councils/junnam/muan.py @@ -5,20 +5,27 @@ from scrap.utils.requests import get_soup import re -def scrap_muan(url = 'http://www.muan.or.kr/main/incumbentCouncillor.do?PID=0201') -> ScrapResult: - '''무안 페이지에서 의원 상세약력 스크랩 + +def scrap_muan( + url="http://www.muan.or.kr/main/incumbentCouncillor.do?PID=0201", +) -> ScrapResult: + """무안 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('ul', class_='formerCouncillor')[0] + mlist = soup.find_all("ul", class_="formerCouncillor")[0] - for profile in mlist.find_all('li', recursive=False): - info = profile.find('div', class_='profileInfo') - name = info.find("div", class_="infosubmem_name").get_text(strip=True) if info.find("div", class_="infosubmem_name").get_text(strip=True) else "이름 정보 없음" + for profile in mlist.find_all("li", recursive=False): + info = profile.find("div", class_="profileInfo") + name = ( + info.find("div", class_="infosubmem_name").get_text(strip=True) + if info.find("div", class_="infosubmem_name").get_text(strip=True) + else "이름 정보 없음" + ) party_dd = info.find("div", class_="infoContents") party = "정당 정보 없음" @@ -27,10 +34,9 @@ def scrap_muan(url = 'http://www.muan.or.kr/main/incumbentCouncillor.do?PID=0201 councilors.append(Councilor(name=name, party=party)) return ScrapResult( - council_id="muan", - council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + council_id="muan", council_type=CouncilType.LOCAL_COUNCIL, councilors=councilors ) -if __name__ == '__main__': - print(scrap_muan()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_muan()) diff --git a/scrap/local_councils/junnam/wando.py b/scrap/local_councils/junnam/wando.py index 5dc3806..dc90a26 100644 --- a/scrap/local_councils/junnam/wando.py +++ b/scrap/local_councils/junnam/wando.py @@ -5,27 +5,31 @@ from scrap.utils.requests import get_soup import requests -def scrap_wando(url = 'http://www.wdcc.or.kr:8088/common/selectCouncilMemberList.json?searchCsDaesoo=9') -> ScrapResult: - '''완도군 페이지에서 의원 상세약력 스크랩 + +def scrap_wando( + url="http://www.wdcc.or.kr:8088/common/selectCouncilMemberList.json?searchCsDaesoo=9", +) -> ScrapResult: + """완도군 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' + """ councilors: List[Councilor] = [] result = requests.get(url) result_json = result.json() - for profile in result_json['list']: - name = profile['cmNm'] - party = profile['mpParty'] + for profile in result_json["list"]: + name = profile["cmNm"] + party = profile["mpParty"] councilors.append(Councilor(name=name, party=party)) return ScrapResult( council_id="wando", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_wando()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_wando()) diff --git a/scrap/local_councils/junnam/yeonggwang.py b/scrap/local_councils/junnam/yeonggwang.py index efe39f4..e4e38c0 100644 --- a/scrap/local_councils/junnam/yeonggwang.py +++ b/scrap/local_councils/junnam/yeonggwang.py @@ -5,20 +5,27 @@ from scrap.utils.requests import get_soup import re -def scrap_yeonggwang(url = 'https://www.ygcouncil.go.kr/bbs/content.php?co_id=councilors_curr#aside') -> ScrapResult: - '''무안 페이지에서 의원 상세약력 스크랩 + +def scrap_yeonggwang( + url="https://www.ygcouncil.go.kr/bbs/content.php?co_id=councilors_curr#aside", +) -> ScrapResult: + """무안 페이지에서 의원 상세약력 스크랩 :param url: 의원 목록 사이트 url :return: 의원들의 이름과 정당 데이터를 담은 ScrapResult 객체 - ''' - + """ + soup = get_soup(url, verify=False) councilors: List[Councilor] = [] - mlist = soup.find_all('div', class_='councilors_curr2_wrap')[0] + mlist = soup.find_all("div", class_="councilors_curr2_wrap")[0] - for profile in mlist.find_all('div',class_="subcon_body_txt", recursive=False): - info = profile.find('div', class_='ygmember_txt') - name = info.find("h4").get_text(strip=True).split(" ")[0] if info.find("h4").get_text(strip=True) else "이름 정보 없음" + for profile in mlist.find_all("div", class_="subcon_body_txt", recursive=False): + info = profile.find("div", class_="ygmember_txt") + name = ( + info.find("h4").get_text(strip=True).split(" ")[0] + if info.find("h4").get_text(strip=True) + else "이름 정보 없음" + ) party_dd = info.find("p", class_="party_highlight") party = "정당 정보 없음" @@ -29,8 +36,9 @@ def scrap_yeonggwang(url = 'https://www.ygcouncil.go.kr/bbs/content.php?co_id=co return ScrapResult( council_id="yeonggwang", council_type=CouncilType.LOCAL_COUNCIL, - councilors=councilors + councilors=councilors, ) -if __name__ == '__main__': - print(scrap_yeonggwang()) \ No newline at end of file + +if __name__ == "__main__": + print(scrap_yeonggwang()) diff --git a/scrap/utils/types.py b/scrap/utils/types.py index 27a64c4..cf16ccc 100644 --- a/scrap/utils/types.py +++ b/scrap/utils/types.py @@ -5,11 +5,14 @@ from typing import Optional, List from dataclasses import dataclass from enum import Enum + + class CouncilType(str, Enum): """ 의회의 종류를 나타내는 열거형입니다. """ - LOCAL_COUNCIL = "local_council" + + LOCAL_COUNCIL = "local_council" """ 기초의회 """ @@ -17,11 +20,14 @@ class CouncilType(str, Enum): """ 광역의회 """ + def __str__(self): """ JSON으로 직렬화하기 위해 문자열로 변환하는 함수를 오버라이드합니다. """ return str(self.value) + + from db.types import CouncilType, Councilor diff --git a/test.py b/test.py index 2a0f446..a3c2a3c 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,9 @@ name = "한양" + def change(a): name = a + + change("고려") -print(name) \ No newline at end of file +print(name)