분류 전체보기
-
PySpiderProject 2023. 7. 8. 11:24
Pyspider는 웹 크롤링을 위해 개발된 모듈이다. 웹 크롤링에는 2가지 지켜야할 특성이 있다. 1. 100-200개의 웹사이트를 수집했을 시 그들은 온/오프라인에서 그들의 템플릿을 때때로 변화시킨다. - 우리는 웹사이트의 변화 여부를 확인하기 위해 강력한 감시도구가 필요하며, 각각의 웹사이트에 스크립트(템플릿)를 작성하게 해주는 좋은 도구가 필요하다. 2. 데이터는 반드시 웹사이트가 업데이트 되었을 때 5분 내로 수집되어야만 한다. - 다음과 같은 문제를 인덱스 페이지를 빈번하게 확인하고, 최근 업데이트 시간(혹은 최근 응답 시간)과 같은 것들을 사용해 페이지의 변화요부를 확인함으로써 해결하였다. 게다가, 우리는 빠진 부분이 없는지 확인하기 위해 x일 이후 페이지들을 재확인한다. Pyspider는 w..
-
23. 폰켓몬Programmers 2023. 7. 4. 08:53
문제 설명 당신은 폰켓몬을 잡기 위한 오랜 여행 끝에, 홍 박사님의 연구실에 도착했습니다. 홍 박사님은 당신에게 자신의 연구실에 있는 총 N 마리의 폰켓몬 중에서 N/2마리를 가져가도 좋다고 했습니다. 홍 박사님 연구실의 폰켓몬은 종류에 따라 번호를 붙여 구분합니다. 따라서 같은 종류의 폰켓몬은 같은 번호를 가지고 있습니다. 예를 들어 연구실에 총 4마리의 폰켓몬이 있고, 각 폰켓몬의 종류 번호가 [3번, 1번, 2번, 3번]이라면 이는 3번 폰켓몬 두 마리, 1번 폰켓몬 한 마리, 2번 폰켓몬 한 마리가 있음을 나타냅니다. 이때, 4마리의 폰켓몬 중 2마리를 고르는 방법은 다음과 같이 6가지가 있습니다. 첫 번째(3번), 두 번째(1번) 폰켓몬을 선택 첫 번째(3번), 세 번째(2번) 폰켓몬을 선택 첫..
-
웹 크롤링 데이터를 MySQL에 저장하기Project 2023. 7. 3. 12:08
Mac에 Mysql 설치 brew install mysql brew install mysql-client MySQL 실행 $ mysql.server start Mysql 데이터베이스 및 유저 생성 mysql > CREATE DATABASE crawl_data DEFAULT CHARACTER SET utf8; mysql > CREATE USER crawl_usr IDENTIFIED BY 'Test001'; exit 입력 후, Python으로 Mysql 접속 코드 만들기 import MySQLdb conn = MySQLdb.connect( user="crawl_usr", passwd="Test001", host="localhost", db="crawl_data" # charset="utf-8" ) print..
-
Requests 알아보기Project 2023. 6. 28. 15:45
오늘은 웹 크롤러를 만들기 전에, Python의 requests에 알아보자. Requests 공식 문서는 다음과 같다. https://requests.readthedocs.io/en/latest/ Requests: HTTP for Humans™ — Requests 2.31.0 documentation Requests: HTTP for Humans™ Release v2.31.0. (Installation) Requests is an elegant and simple HTTP library for Python, built for human beings. Behold, the power of Requests: >>> r = requests.get('https://api.github.com/user', auth..
-
Client와 Server, REST API, JSONProject 2023. 6. 26. 16:58
* Client 정보를 요청하는 측이 클라이언트, 요청을 받아 응답하는 쪽이 서버이다. 클라이언트가 서버로 데이터를 보내는 것을 Request라고 한다. 단순한 검색부터 상품 결제까지 전부 웹 서버로 요청을 보내야 한다. 이러한 요청은 데이터의 모음으로 네트워크를 통해 서버에게 전달되며, 서버로 요청을 보낸 이후 응답이 올 때까지 기다리는 것이 클라이언트의 역할이다. 클라이언트는 HTML, 자바스크립트, CSS 코드를 적절히 화면에 출력하는 기능을 수행한다. 이때 클라이언트는 출력만을 담당하며, 정보를 생성하고 보내는 역할은 전적으로 서버가 담당한다. 웹뿐만 아니라 온라인 게임에서도 유사한데, 게임 배경 화면이나 캐릭터 이미지 같은 그래픽 파일은 PC에 미리 저장되어 있고, 게임 플레이 도중에 서버로부터..
-
22. 암호 만들기Programmers 2023. 6. 26. 15:54
최백준 조교가 방 열쇠를 주머니에 넣은 채 깜빡하고 서울로 가버리는 황당한 상황에 직면한 조교들은 702호에 새로운 보안 시스템을 설치하기로 하였다. 이 보안 시스템은 열쇠가 아닌 암호로 동작하는 시스템이다. 암호는 서로 다른 L개의 알파벳 소문자들로 구성되며 최소 한 개의 모음과 최소 두 개의 자음으로 구성되어 있다고 알려져 있다. 또한 정렬된 문자열을 선호하는 조교들의 성향으로 미루어보아 암호를 이루는 알파벳이 암호에서 증가하는 순서로 배열되었을 것이라고 추측된다. (abc는 가능성이 있는 암호이나 bac는 아니다) 새 보안 시스템에서 조교들이 암호로 사용했을 법한 문자는 C가지가 있다. 이 알파벳을 입수한 민식, 영식 형제는 조교들의 방에 침투하기 위해 암호를 추측해보려고 한다. from itert..
-
21. N개의 최소공배수Programmers 2023. 6. 25. 16:31
문제 설명 두 수의 최소공배수(Least Common Multiple)란 입력된 두 수의 배수 중 공통이 되는 가장 작은 숫자를 의미합니다. 예를 들어 2와 7의 최소공배수는 14가 됩니다. 정의를 확장해서, n개의 수의 최소공배수는 n 개의 수들의 배수 중 공통이 되는 가장 작은 숫자가 됩니다. n개의 숫자를 담은 배열 arr이 입력되었을 때 이 수들의 최소공배수를 반환하는 함수, solution을 완성해 주세요. 제한 사항 arr은 길이 1이상, 15이하인 배열입니다. arr의 원소는 100 이하인 자연수입니다. def solution(arr): answer = max(arr) mx = [i for i in arr if answer%i != 0] for x in mx: for i in range(2,..
-
20. 소수 만들기Programmers 2023. 6. 24. 14:40
문제 설명 주어진 숫자 중 3개의 수를 더했을 때 소수가 되는 경우의 개수를 구하려고 합니다. 숫자들이 들어있는 배열 nums가 매개변수로 주어질 때, nums에 있는 숫자들 중 서로 다른 3개를 골라 더했을 때 소수가 되는 경우의 개수를 return 하도록 solution 함수를 완성해주세요. 제한사항 nums에 들어있는 숫자의 개수는 3개 이상 50개 이하입니다. nums의 각 원소는 1 이상 1,000 이하의 자연수이며, 중복된 숫자가 들어있지 않습니다. from itertools import combinations def solution(nums): num = [sum(i) for i in list(combinations(nums, 3))] answer = len(num) for n in num:..