카테고리 없음
[requests] with requests.Session() as s: 로그인 세션 생성 및 데이터 가져오기
0w0
2019. 8. 19. 06:10
728x90
반응형
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 54 55 56 57 58 59 60 61 62 63 64 65 | #[requests] with requests.Session() as s: 로그인 세션 생성 및 데이터 가져오기 import sys,io,time import requests from bs4 import BeautifulSoup LOGIN_INFO={ 'email': "---------", 'password': "----------" } #세션 유지 with requests.Session() as s: #로그인 정보 전송 login_response=s.post('https://www.inflearn.com/api/signin',data=LOGIN_INFO) print("로그인 요청의 응답 : ",login_response) print("로그인 요청의 응답 헤더 : ",login_response.headers) print(login_response.status_code) print(login_response.ok) if login_response.status_code==200 and login_response.ok: #강의 목록 파싱을 위한 URI 접근 및 코드 가져오기 html=s.get('https://www.inflearn.com/courses/it-programming') #예외 처리 및 에러 정보 제공 html.raise_for_status() #soup 변환 soup=BeautifulSoup(html.text,'html.parser') #강의 목록 파싱 data1=soup.findAll('div',{'class':'course_title'}) data1=[tmp.text for tmp in data1] data2=[tmp[9:] for tmp in data1] data2=[tmp[:-7] for tmp in data2] for tmp in data2: print(tmp) print("=============") #닉네임 파싱을 위한 URI 접근 및 코드 가져오기 html=s.get('https://www.inflearn.com/users/59811/dashboard') # 예외 처리 및 에러 정보 제공 html.raise_for_status() #soup 변환 soup=BeautifulSoup(html.text,'html.parser') #계정 정보 파싱 data1=soup.find('div',{'class':'media-content'}) data1=data1.text data1=data1.split() data1=data1[0] data1=data1[:-2] print(data1) | cs |
728x90
반응형