본문 바로가기

Research/Python25

BeautifulSoup_Basics Install pip install bs4 pip install requests pip install lxml Basics bs4는 requests와 lxml 파서에 의존한다. 여러 라이브러리에 의존하기 때문에 프로젝트가 고도화되면 bs4를 잘 쓰지 않는다. from bs4 import BeautifulSoup import requests # 1) Fetch the pages (obtained a response object) result = requests.get('www.google.com') # 2) Page content content = result.text # 3) Create soup soup = BeautifulSoup(content, "lxml") # 4) Finding elements .. 2023. 3. 25.
Python_웹 스크래핑을 위한 기본 문법 # All the datas are same data type states = ["California", "Texas", "Florida", "New York"] # Indexing # 파이썬은 0 based list print(states[0]) # California print(states[3]) # New York print(states[-1]) # New York print(states[-4]) #California # For loop for state in states: # If statement if state == "Florida": print(state); # create file by writing # open.. 블라블라를 file로 치환 # 실행하면 실제 txt 파일이 생성된다 wit.. 2023. 3. 25.
bs4로 지니뮤직 스크래핑하여 mongoDB에 저장하기 bs4로 지니뮤직 스크래핑하여 mongoDB에 저장하기 스크래핑 타겟 : https://www.genie.co.kr/chart/top200?ditc=M&rtm=N&ymd=20210701 스크래핑 하기 MongoClient에 들어갈 와 에는 각자 mongoDB의 아이디와 비밀번호를 넣어주면 된다. import requests from bs4 import BeautifulSoup from pymongo import MongoClient client = MongoClient('mongodb+srv://:@cluster0.5hnlvb6.mongodb.net/?retryWrites=true&w=majority') db = client.dbsparta target = 'https://www.genie.co.kr/c.. 2022. 11. 22.
bs4 select() method cheat sheet 2022. 11. 21.