본문 바로가기
반응형

파이썬4

[Flask] 직렬화 오류 raise TypeError(f"Object of type {type(o).__name__} is not JSON serializable") TypeError: Object of type Cursor is not JSON serializable 으이구! 커서 객체를 json으로 바꾸려니까 에러가 나쥬! from flask import Flask, jsonify, request from pymongo import MongoClient collection.find()은 컬렉션에서 조건 없이 모든 문서를 조회하는 메서드다. 이를 호출하면 커서(Cursor) 객체가 반환 되는데, 커서는 실제 데이터를 포함하고 있는 반복 가능한 객체다. list(collection.find())을 사용하면 커서 객체를 리스트로 .. 2023. 7. 3.
Selenium + MongoDB 크롤링한 데이터 저장하기 파이썬에서 MongoDB에 리스트를 삽입하는 방법은 다음과 같습니다. 1. pymongo 라이브러리 설치 pymongo는 파이썬에서 MongoDB를 다루는 데 사용되는 공식 MongoDB 드라이버입니다. 설치는 pip 명령어를 사용하여 다음과 같이 수행할 수 있습니다. pip install pymongo 2. MongoDB 관련 클래스를 만듭니다. from pymongo import MongoClient class MongoDB: def __init__(self): # MongoDB에 연결 self.client = MongoClient('localhost', 27017) # 데이터베이스 선택 (없는 경우 자동으로 생성됨) self.db = self.client['test'] # 컬렉션 선택 (없는 경우 .. 2023. 7. 1.
Python + Selenium 도메인 여러 개 크롤링하기 도메인 여러 개를 리스트에 넣어두고 여러 사이트를 순차적으로 크롤링할 수 있는 방법에 대해 설명해보도록 하겠습니다. url에 따라 선택자를 다르게 설정하여 코드를 작성할 수 있습니다. 아래 코드를 참조해주세요. from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import re driver = webdriver.Chrome() urls = ['https://example.com/a', 'https://exam.. 2023. 6. 30.
Python + Selenium 특정 요소가 로드된 후 원하는 데이터 가지고 오기(선택자 종류 소개) 2023.06.29 - [공부기록/파이썬] - Python + Selenium으로 크롤링 시작하기(예제 있음) 파이썬에서 셀레니움을 시작하는 방법은 위 글을 참조해주세요. * WebDriverWait 클래스와 expected_conditions 모듈을 사용하여 특정 요소가 로드된 이후 원하는 데이터를 가지고 올 수 있습니다. * 아래 코드를 참조해주세요.from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 웹.. 2023. 6. 30.
728x90
반응형