-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_crawiling.py
More file actions
53 lines (46 loc) · 1.98 KB
/
Copy pathdb_crawiling.py
File metadata and controls
53 lines (46 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import requests
from bs4 import BeautifulSoup
from pymongo import MongoClient # pymongo를 임포트 하기(패키지 인스톨 먼저 해야겠죠?)
client = MongoClient('localhost', 27017) # mongoDB는 27017 포트로 돌아갑니다.
db = client.dbsparta # 'dbsparta'라는 이름의 db를 사용합니다. 'dbsparta' db가 없다면 새로 만듭니다.
movie_list = list(db.movies.find({}))
for movie_same in movie_list:
if movie_same['star'] == '9.59':
print(movie_same['title'])
#todo 그린북과 같은 평점의 list name 뽀기
# # 타겟 URL을 읽어서 HTML를 받아오고,
# headers = {
# 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36'}
# data = requests.get('https://movie.naver.com/movie/sdb/rank/rmovie.nhn?sel=pnt&date=20200716', headers=headers)
#
# # HTML을 BeautifulSoup이라는 라이브러리를 활용해 검색하기 용이한 상태로 만듦
# # soup이라는 변수에 "파싱 용이해진 html"이 담긴 상태가 됨
# # 이제 코딩을 통해 필요한 부분을 추출하면 된다.
# soup = BeautifulSoup(data.text, 'html.parser')
#
# # select를 이용해서, tr들을 불러오기
# movies = soup.select('#old_content > table > tbody > tr')
#
# # movies (tr들) 의 반복문을 돌리기
# for movie in movies:
# # movie 안에 a 가 있으면,
# a_tag = movie.select_one('td.title > div > a')
# if a_tag is not None:
# # a의 text를 찍어본다.
# rank = movie.select_one('td:nth-child(1) > img')['alt'] # img 태그의 alt 속성값을 가져오기
# title = a_tag.text # a 태그 사이의 텍스트를 가져오기
# star = movie.select_one('td.point').text # td 태그 사이의 텍스트를 가져오기
#
#
# dic = {
# 'rank':rank,
# 'title':title,
# 'star':star
#
# }
# db.movies.insert_one(dic)
# print(dic)
#
#
#
# print(rank, title, star)