Coding 63

selenium ์‚ฌ์šฉ์‹œ url ์ฃผ์†Œ ์ž…๋ ฅ์ด ์•ˆ๋ ๋•Œ

์…€๋ ˆ๋‹ˆ์›€์„ ์‚ฌ์šฉํ•˜์—ฌ ํฌ๋กฌ ๋“œ๋ผ์ด๋ฒ„๋กœ ์ž๋™ํ™”ํ•˜๋Š”๋ฐ, ์•„๋ฌด๋ฆฌ driver.get(url) ํ•ด๋„ invalidargument exception์ด ๋œฐ ๋•Œ. 1) url ์ด string ๊ฐ’์ธ์ง€ ํ™•์ธํ•œ๋‹ค. 2) https://๋ฅผ ์•ž์— ๋ถ™์—ฌ๋ณธ๋‹ค. ๋‚ด ๊ฒฝ์šฐ๋Š” m.~~~~๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ฃผ์†Œ์˜€๋Š”๋ฐ, ์ด ์ฃผ์†Œ๋ฅผ ๋งํฌ๋กœ ์ธ์‹์„ ๋ชปํ•ด์„œ ์ƒ๊ธฐ๋Š” ๋ฌธ์ œ์˜€๋‹ค. suffix = "https://" driver.get( suffix + url ) ํ•˜๋‹ˆ๊นŒ ๋˜์—ˆ์Œ

Coding 2023.09.21

[python] ์œ ํŠœ๋ธŒ ๋Œ“๊ธ€ ํฌ๋กค๋ง(api ์‚ฌ์šฉ)

์œ ํŠœ๋ธŒ api ๊ฐ€์„œ ํ‚ค๊ฐ’์„ ๋ฐœ๊ธ‰๋ฐ›์€ ํ›„, ์•„๋ž˜์™€ ๊ฐ™์ด ์„ค์น˜ํ•ด์ฃผ๊ณ , pip install google-api-python-client import re import datetime from tqdm import tqdm tvNdrama ์ฑ„๋„์˜ ์žฌ์ƒ ๋ฆฌ์ŠคํŠธ๋ฅผ ํ™•์ธํ•˜๊ณ , ํŠน์ • ์žฌ์ƒ๋ฆฌ์ŠคํŠธ์˜ ๋Œ“๊ธ€์„ ๋ชจ๋‘ ๊ฐ€์ ธ์˜ค๊ณ  ์‹ถ์„๋•Œ from googleapiclient.discovery import build from googleapiclient.errors import HttpError # from oauth2client.tools import argparser DEVELOPER_KEY = ' ' # ๋‚ด ์œ ํŠœ๋ธŒ API ํ‚ค YOUTUBE_API_SERVICE_NAME = 'youtube' YOUTUBE_API_VERSION ..

Coding/Python 2022.04.06

[python] ์œ ํŠœ๋ธŒ ๋Œ“๊ธ€ ํฌ๋กค๋ง(api ์—†์ด)

์œ ํŠœ๋ธŒ ์˜์ƒ์„ ๊ฒ€์ƒ‰ํ•˜์—ฌ, ๋‚˜์˜ค๋Š” ์˜์ƒ๋“ค์˜ ๋Œ“๊ธ€์„ ๋ชจ๋‘ ์ˆ˜์ง‘ํ•ด์•ผ ํ–ˆ๋‹ค. ์—ฌ๋Ÿฌ ์ฐธ๊ณ  ์ž๋ฃŒ๋ฅผ ํ™œ์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์™„์„ฑ์‹œ์ผฐ๋‹ค. import pandas as pd from bs4 import BeautifulSoup from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from tqdm import tqdm import time import re import requests import random import datetime #Queue์˜ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋Šฅ ๊ตฌํ˜„ class Queue(): def __init__(self, maxsize): self.queue = [] self.maxsize = maxs..

Coding/Python 2022.04.06

[Python] Numpy

Numpy์†Œ๊ฐœ ๋ฐ ํ•„์š”์„ฑ Numerocal Python์˜ ์•ฝ์–ด ๋จธ์‹ /๋”ฅ, ๋ฐ์ดํ„ฐ ์ „์ฒ˜๋ฆฌ ํ•„์ˆ˜ api ๋จธ์‹ ๋Ÿฌ๋‹์˜ ์ฃผ์š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ์„ ํ˜•๋Œ€์ˆ˜์™€ ํ†ต๊ณ„ ๊ธฐ๋ฐ˜ ์„ ํ˜•๋Œ€์ˆ˜ ๊ธฐ๋ฐ˜์˜ ํ”„๋กœ๊ทธ๋žจ์„ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•˜๋Š” ๋Œ€ํ‘œ์ ์ธ package ๋ฒกํ„ฐ ๋ฐฐ์—ด์ƒ์—์„œ ๋ฐ์ดํ„ฐ ๊ฐœ์กฐ, ์ •์ œ, ๋ถ€๋ถ„ ์ง‘ํ•ฉ, ํ•„ํ„ฐ๋ง, ๋ณ€ํ˜•, ๋‹ค๋ฅธ ์ข…๋ฅ˜ ์—ฐ์‚ฐ์˜ ๋น ๋ฅด ์ˆ˜ํ–‰ if-elif-else๋ฅผ ํ‘œํ˜„ํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ ๋Œ€์‹  ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์กฐ๊ฑด์ ˆ์„ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฐ์—ดํ‘œํ˜„ ๊ธฐ๋ณธ python์—์„  list๋กœ ํ‘œํ˜„ํ•˜๋‚˜, numpy์—์„œ๋Š” ndarray๋กœ ํ‘œํ˜„ Numpy์˜ ๋ฐ์ดํ„ฐ ํ‘œํ˜„ ๋‹จ์œ„ Numpy์˜ ์šฉ์–ด axis: ๊ฐ’๋“ค์˜ ๋‚˜์—ด ๋ฐฉํ–ฅ rank : ๋ฐ์ดํ„ฐ ์ง‘ํ•ฉ์—์„œ์˜ ์ถ•์˜ ๊ฐœ์ˆ˜ shape : ํ˜•์ƒ / ํ˜•ํƒœ, ๊ฐ ์ถ• ๋ณ„ ๋ฐ์ดํ„ฐ ๊ฐœ์ˆ˜ size ๋ฒกํ„ฐํ™” : ๋ฐฐ์—ด์˜ ๊ฐ ์›์†Œ์— ๋Œ€..

Coding/Python 2022.03.18

[Python] ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™”

๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” ๋ชฉ์  ๋ฐ์ดํ„ฐ ํƒ์ƒ‰์„ ํ•  ๋•Œ ๊ฐ€์žฅ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์‹œ๊ฐํ™” ๋ฐ์ดํ„ฐ์˜ ํฌ๊ธฐ๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ฒƒ ์ˆ˜์น˜๊ฐ’์„ ํ•˜๋‚˜์”ฉ ๋ณด๋Š” ๊ฒƒ๋ณด๋‹ค ๊ทธ๋ฆผ์„ ๋ณด๋ฉด ๋ฐ์ดํ„ฐ์— ์กด์žฌํ•˜๋Š” ํŒจํ„ด์„ ์‰ฝ๊ฒŒ ์•Œ์•„๋ณผ ์ˆ˜ ์žˆ์Œ ๋ฐ์ดํ„ฐ ๋ถ„์„ ๊ฒฐ๊ณผ ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ์ •ํ™•ํ•œ ๋ถ„์„์„ ์œ„ํ•ด ๋ฐ์ดํ„ฐ ํƒ์ƒ‰ ๋ฐฉ๋ฒ•์œผ๋กœ ํ™œ์šฉ ๋ถ„์„์‹œ์— ์ตœ์ ํ™”๋œ ๋ฐ์ดํ„ฐ ๊ตฌ์กฐ๋กœ ๋ถ„์„์„ ์š”ํ•  ๊ฒฝ์šฐ ๊ธˆ์ „์ ์ธ ํšจ๊ณผ๊ฐ€ ์ฐฝ์ถœ ๊ธฐ์กด ๋ถ„์„๊ณผ์˜ ์ฐจ๋ณ„์  ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๊ธฐ ์œ„ํ•ด ์žฅ๋น„๋นจ์ด ํ•„์š” ๋ฐ์ดํ„ฐ ์‹œ๊ฐํ™” ํ”„๋กœ์„ธ์Šค ์ƒํ™ฉ์„ ์ดํ•ดํ•ด์•ผ ํ•จ ๋ˆ„๊ฐ€ ๋ณด๋Š” ๊ฒƒ์ธ์ง€? ๋ฌด์—‡์„ ๋ณด๋Š” ๊ฒƒ์ธ์ง€? ์–ด๋–ป๊ฒŒ ๋ณด๋Š” ๊ฒƒ์ธ์ง€? ๋ˆ„๊ตฌ๋ฅผ ๋Œ€์ƒํ•˜๋Š” ๊ฒƒ์ธ์ง€? ์ ํ•ฉํ•œ ์‹œ๊ฐํ™” ๋ฐฉ๋ฒ• ์„ ํƒ ๋ถˆํ•„์š”ํ•œ ์š”์†Œ ์ œ๊ฑฐ (๊ฐ€์žฅ ์ค‘์š”) ์›ํ•˜๋Š” ๊ณณ์— ์ง‘์ค‘ํ•˜๋„๋ก ์œ ๋„ ๊ฒฐ๊ณผ์ ์œผ๋กœ ํ•˜๋‚˜์˜ ์Šคํ† ๋ฆฌ๊ฐ€ ๋งŒ๋“ค์–ด์ง ๊ฒฐ๋ก  : ๋ฐ์ดํ„ฐ๋กœ๋ถ€ํ„ฐ ์ˆจ์€ ์ด์•ผ๊ธฐ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”..

Coding/Python 2022.03.16

[Python] ์—๋Ÿฌ : python-3.x Couldn't find Class NSProcessInfo

๊ฐ€์ƒํ™˜๊ฒฝ์„ ์ƒ์„ฑํ•˜๊ณ (python 3.6) ์ฃผํ”ผํ„ฐ ๋…ธํŠธ๋ถ์„ ์‹คํ–‰ํ–ˆ๋Š”๋ฐ kernel์ด ์—ฐ๊ฒฐ์ด ์•ˆ๋˜๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ–ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๊ฐ€ ํ„ฐ๋ฏธ๋„ ์ฐฝ์— ์ถœ๋ ฅ๋จ AssertionError: Couldn't find Class NSProcessInfo Mac์˜ Big Sur OS ์—์„œ ๋ฐœ์ƒํ•˜๋Š” ์—๋Ÿฌ์ผ ํ™•๋ฅ ์ด ๋†’๋‹ค๊ณ  ํ•œ๋‹ค. - ๋งฅ์—์„œ ํŒŒ์ด์ฌ ์ฃผํ”ผํ„ฐ๋ฅผ ์“ธ ๋•, 3.8 ์ด์ƒ์„ ์“ฐ๋„๋ก ํ•˜์ž. Running a Jupyter Lab kernel under Python 3.6 (possibly also 3.7) throws: AssertionError: Couldn't find Class NSProcessInfo Running in Python 3.8 works fine. https://stackoverflow.co..

Coding/Python 2022.03.16

[Python] Module

๋ชจ๋“ˆ(๋ฌถ์Œ)์ด๋ž€? ํ•จ์ˆ˜๋‚˜ ๋ณ€์ˆ˜๋“ค์„ ๋ชจ์•„ ๋†“์€ library๋“ค ์˜๋ฏธ ํšŒ์‚ฌ, ๊ทธ๋ฃน, ๋ชจ๋ฅด๋Š” ๋ˆ„๊ตฐ๊ฐ€๊ฐ€ ์ œ๊ณตํ•˜๋Š” ์™ธ๋ถ€ library๋“ค ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•, ์™ธ๋ถ€์— ๋‚ด ์ฝ”๋“œ๋ฅผ ๊ณต์œ ํ•˜๋Š” ๋ฐฉ๋ฒ• ๋ชจ๋“ˆ ์‚ฌ์šฉ ๋ฐฉ๋ฒ• 2-1. ๋ชจ๋“ˆ์˜ ํŒŒ์ผ ํ™•์žฅ์ž : py 2-2. ๋ชจ๋“ˆ ์‚ฌ์šฉ ๋ฌธ๋ฒ• a. import file๋ช… b. from file๋ช… import ํ•จ์ˆ˜๋ช… c. import file๋ช… as ๋ณ„์นญ %%writefile mymath.py #mymath.py๋ฅผ ํŒŒ์ผ๋กœ ์ €์žฅ mypi = 3.14 def add(a,b): return a+b def area(r): return r*r*mypi mymath ๋ชจ๋“ˆ์˜ ๊ฐ ๋ฉ”์†Œ๋“œ ํ˜ธ์ถœ ๋ฐ ์ถœ๋ ฅ # from file๋ช… import ํ•จ์ˆ˜๋ช…1 [, ํ•จ์ˆ˜๋ช…2] import mymath as m print(m...

Coding/Python 2022.03.07

220307_code everyday(์ˆซ์ž ์นด๋“œ2)

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช… ์ˆซ์ž ์นด๋“œ๋Š” ์ •์ˆ˜ ํ•˜๋‚˜๊ฐ€ ์ ํ˜€์ ธ ์žˆ๋Š” ์นด๋“œ์ด๋‹ค. ์ƒ๊ทผ์ด๋Š” ์ˆซ์ž ์นด๋“œ N๊ฐœ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. ์ •์ˆ˜ M๊ฐœ๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ด ์ˆ˜๊ฐ€ ์ ํ˜€์žˆ๋Š” ์ˆซ์ž ์นด๋“œ๋ฅผ ์ƒ๊ทผ์ด๊ฐ€ ๋ช‡ ๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค. ๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ ์ฒซ์งธ ์ค„์— ์ƒ๊ทผ์ด๊ฐ€ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์˜ ๊ฐœ์ˆ˜ N(1 ≤ N ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋‘˜์งธ ์ค„์—๋Š” ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ์ˆซ์ž ์นด๋“œ์— ์ ํ˜€์žˆ๋Š” ์ˆ˜๋Š” -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ๊ฐ™๊ณ , 10,000,000๋ณด๋‹ค ์ž‘๊ฑฐ๋‚˜ ๊ฐ™๋‹ค. ์…‹์งธ ์ค„์—๋Š” M(1 ≤ M ≤ 500,000)์ด ์ฃผ์–ด์ง„๋‹ค. ๋„ท์งธ ์ค„์—๋Š” ์ƒ๊ทผ์ด๊ฐ€ ๋ช‡ ๊ฐœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ์ˆซ์ž ์นด๋“œ์ธ์ง€ ๊ตฌํ•ด์•ผ ํ•  M๊ฐœ์˜ ์ •์ˆ˜๊ฐ€ ์ฃผ์–ด์ง€๋ฉฐ, ์ด ์ˆ˜๋Š” ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„๋˜์–ด์ ธ ์žˆ๋‹ค. ์ด ์ˆ˜๋„ -10,000,000๋ณด๋‹ค ํฌ๊ฑฐ..

220302_Code in the morning(์†Œ์ˆ˜ ๋งŒ๋“ค๊ธฐ)

๐Ÿ’ฌ ๋ฌธ์ œ ์„ค๋ช… ํ•œ์ž๋ฆฌ ์ˆซ์ž๊ฐ€ ์ ํžŒ ์ข…์ด ์กฐ๊ฐ์ด ํฉ์–ด์ ธ์žˆ์Šต๋‹ˆ๋‹ค. ํฉ์–ด์ง„ ์ข…์ด ์กฐ๊ฐ์„ ๋ถ™์—ฌ ์†Œ์ˆ˜๋ฅผ ๋ช‡ ๊ฐœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š”์ง€ ์•Œ์•„๋‚ด๋ ค ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ ์ข…์ด ์กฐ๊ฐ์— ์ ํžŒ ์ˆซ์ž๊ฐ€ ์ ํžŒ ๋ฌธ์ž์—ด numbers๊ฐ€ ์ฃผ์–ด์กŒ์„ ๋•Œ, ์ข…์ด ์กฐ๊ฐ์œผ๋กœ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ์†Œ์ˆ˜๊ฐ€ ๋ช‡ ๊ฐœ์ธ์ง€ return ํ•˜๋„๋ก solution ํ•จ์ˆ˜๋ฅผ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ๐Ÿ“ ์ œํ•œ ์‚ฌํ•ญ numbers๋Š” ๊ธธ์ด 1 ์ด์ƒ 7 ์ดํ•˜์ธ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. numbers๋Š” 0~9๊นŒ์ง€ ์ˆซ์ž๋งŒ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ์Šต๋‹ˆ๋‹ค. "013"์€ 0, 1, 3 ์ˆซ์ž๊ฐ€ ์ ํžŒ ์ข…์ด ์กฐ๊ฐ์ด ํฉ์–ด์ ธ์žˆ๋‹ค๋Š” ์˜๋ฏธ์ž…๋‹ˆ๋‹ค. ๐Ÿ’ก ๋‚˜์˜ ํ’€์ด from itertools import permutations answer = [] def solution(numbers): nums = [n for n in numbers] # nu..

๋ฐ์ดํ„ฐ ์ €์žฅ์‹œ ์ธ์ฝ”๋”ฉ ์˜ค๋ฅ˜

ํฌ๋กค๋ง ํ›„ ๋ฐ์ดํ„ฐ ์ €์žฅ์‹œ ์ธ์ฝ”๋”ฉ์„ utfmb4๋กœ ์„ค์ •ํ–ˆ๋Š”๋ฐ๋„ 'utf-8' codec can't encode characters in position 188-189: surrogates not allowed ์˜ค๋ฅ˜๊ฐ€ ๋œจ๋ฉด ์ด๋ชจํ‹ฐ์ฝ˜ ์˜ค๋ฅ˜๋ฅผ ๊ณ ๋ คํ•ด๋ณด์ž. ์ด๋ชจ์ง€๋ฅผ ์ œ๊ฑฐํ•˜๋Š” ํ•จ์ˆ˜ ๋งŒ๋“ค์–ด์„œ ์‚ฌ์šฉํ•ด ํ•ด๊ฒฐ! def rmEmoji(inputData): return inputData.encode('utf-8', 'ignore').decode('utf-8')

Coding/Python 2022.02.21