Development

Development

[Python] 웹사이트에서 링크 목록 수집하기

이번 글에서는 파이썬을 사용해 웹사이트에서 링크 목록을 수집해오는 예제에 대해 소개하려 한다. 간단히 얘기하면 BeautifulSoup 모듈을 사용해 웹사이트를 받아와 특정 태그에 해당하는 항목들을 수집해오는 예제이다. 샘플 코드 예제에서 사용한 웹사이트는 https://example.com/ 으로 실제로 사이트에 들어가면 아래와 같은 화면이 나온다. 샘플 코드는 이 웹사이트의 제목과 링크(More information...)가 바라보는 사이트의 주소를 가져오는 기능을 수행한다. import requests from bs4 import BeautifulSoup url = 'https://example.com' response = requests.get(url) soup = BeautifulSoup(res..

Development

[Python] 문장에서 가장 긴 단어 찾기

문장을 입력받아 가장 긴 단어를 찾는 예제를 작성해 보았다. 샘플코드 def find_longest_word(sentence): words = sentence.split() return max(words, key=len) # Example usage text = "It only takes about 20 minutes to find out about your accurate English level" print("Longest word:", find_longest_word(text)) 결과 Longest word: accurate

Development

[Python] 문자열 뒤집기

Python으로 문자열을 뒤집는 예제를 작성해 보았다. 샘플 코드 def reverse_string(input_string): return input_string[::-1] # Example usage text = "Hello, World!" print("Reversed text:", reverse_string(text)) 입력으로 받은 string의 interval을 -1로 설정하면 문자열이 뒤집히게 된다. 결과 Reversed text: !dlroW ,olleH

Development

[Python] pattern으로 데이터 검증하기

개발을 하다보면 입력값 등의 데이터가 제대로 된 형태인지 검증이 필요한 경우가 있다. 이번 글에서는 pattern을 사용해 데이터를 검증하는 예제를 소개한다. 예제 코드 import re def validate_email(email): pattern = r'^[\w\.-]+@[\w\.-]+\.\w+$' if re.match(pattern, email): return True else: return False # Example usage email_address = input("Enter an email address: ") is_valid = validate_email(email_address) if is_valid: print("Valid email address") else: print("Invali..

Development

[Python] 랜덤 비밀번호 생성하기

Python ramdom 라이브러리를 사용한 랜덤 비밀번호 생성 예제를 소개한다. 샘플 코드 import random def generate_random_password(length): characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*" password = ''.join(random.choice(characters) for _ in range(length)) return password # Example usage password_length = 10 random_password = generate_random_password(password_length) print("Random Password:", ..

Development

[Python] datetime으로 현재 날짜/시간 받아오기

datetime 라이브러리를 사용해 현재 날짜와 시간을 받아오는 방법을 소개한다. datetime 라이브러리 날짜와 시간을 조작하는 다양한 기능을 제공하는 라이브러리. 자세한 설명은 아래 링크에서 확인. https://docs.python.org/ko/3/library/datetime.html datetime — Basic date and time types Source code: Lib/datetime.py The datetime module supplies classes for manipulating dates and times. While date and time arithmetic is supported, the focus of the implementation is on efficient att..

삿뿐삿뿐
'Development' 카테고리의 글 목록