[리뉴얼] 파이썬입문과 크롤링기초 부트캠프 [파이썬, 웹, 데이터 이해 기본까지] (업데이트)
import requests from bs4 import BeautifulSoup res=requests.get('https://comic.naver.com/index.nhn') soup=BeautifulSoup(res.content, 'html.parser') data=soup.select('#realTimeRankFavorite > li > a') for index,item in enumerate (data): print(index+1, "인기웹툰:", item.get_text()) 이렇게 코드를 짜서 인기웹툰 순위 크롤링은 되었는데요. import requests from bs4 import BeautifulSoup res=requests.get('https://comic.naver.com/webtoon/detail.nhn?titleId=743031&no=34&weekday=mon') soup=BeautifulSoup(res.content, 'html.parser') data=soup.select('ul #u_cbox_list') for item in data: print(item.get_text()) #구현시에 아무것도 안뜨는데 혹시 어떤 부분을 수정해야 하는걸까요? 웹툰에 달리는 댓글들을 크롤링해보고 싶은데 검색에 들어가서 copy해서 찾아 넣었는데 실행을 하면 에러코드도 아니고 아예 아무것도 안떠서요. 어디가 잘못된건지.. 혹은 댓글 크롤링은 아예 다른 접근이 필요한건지 문의드려봅니다.
Object . prototype . map = function (f) { const result = []; for ( const el of this ) result. push ( f (el)); return result; }; 제 생각에 이런 식으로 정의를 하면 기존의 Array.prototype.map메서드 처럼 체이닝해서 사용할 수 있을 것 같다고 생각을 했어요. 가독성 측면에서 더 나아지지 않을까 생각을 했습니다. 이렇게 사용했을 때 불리한 점이 있을까 궁금해서 질문드려봅니다.
안녕하세요! 항상 좋은 강의를 제공해주셔서 정말 감사드립니다. 다름이 아니라, 강의를 듣고 별도의 데이터로 실습을 해보고자, 타겟 변수(종속 변수)가 명목형 범주형 변수이고, 독립 변수(예측 변수)가 범주형 변수, 연속형 변수가 섞여져 있는 상황에서 분석 공부를 하다가 궁금한 점이 생겨 질문을 드리게 되었습니다. 1) 독립 변수 중 범주형 변수 중에서, 명목 척도가 아닌 순서 척도를 활용해야 하는 상황인 경우, 원-핫 인코딩으로 진행을 하게 되면 '순서'의 정보를 잃게 되는데, 캐글에서는 ordinal encoding, mean encoding 혹은 target encoding 등을 자주 활용한다고 들었습니다. 보통 분석에서 범주형 변수를 다룰 시, 명목 척도와 순서 척도를 구분하여 서로 다른 인코딩을 적용하는지, 아니면 구분하지 않고 하나의 인코딩을 적용하는지 알고 싶습니다. 2)스케일링에서, 범주형 변수를 인코딩한 후 값이 큰 연속형 변수와 같이 스케일링을 수행해도 되는 것인지, 아니면 스케일링을 연속형 변수에만 수행하는 것인지 알고 싶습니다. 3) corr() 함수는 보통 연속 변수 & 연속 변수 혹은 범주형 순서 척도 & 범주형 순서 척도에 대한 피어슨 상관 계수를 출력하는 것으로 알고 있는데, binary가 아닌 범주형 명목 척도 & 연속형 변수, 그리고 범주형 순서 척도 & 연속형 변수에 대한 상관도는 어떻게 구하는지 알고 싶습니다. 항상 좋은 강의 감사드립니다.
아래처럼 회원 조회 로직이 있을때 멤버 엔티티 정보를 스트림화 한뒤 멤버 디티오 형식으로 다시 설정하고 그걸 리스트화하는것까지는 의미상으로 이해가 가는데여 응답 클래스 Result < T > 객체를 만들어서 응답하는 이유가 무엇인가여? @GetMapping ( "/api/v2/members" ) public Result memberV2 () { List < Member > findMembers = memberService .findMembers(); List < MemberDto > collect = findMembers .stream() .map(m-> new MemberDto(m.getName())) .collect( Collectors . toList ()); return new Result( collect ); } @Data @AllArgsConstructor static class Result < T > { private T data ; } @Data @AllArgsConstructor static class MemberDto { private String name ; }
console입력하고 저장할때 JSLint 'console' was used before it was defined. ESLine ERROR:Unexpected console statement.[no-console] ERROR:'console' is not defined.[no-undef] 해당오류가 표시됩니다. 콘솔이 정의되지않았다고하는데 설정해주는 부분이 있는지 질문드려요.
pdf 파일에 보면 참고: 생성자에 @Autowired 를 사용하면 객체 생성 시점에 스프링 컨테이너에서 해당 스프링 빈을 찾아서 주입한다. 생성자가 1개만 있으면 @Autowired 는 생략할 수 있다. 라고 되어 있습니다. 1. 생성자가 1개라는게 주입받을 빈이 1개라는 의미 인가요? 2. 1번의 의미가 맞다면 생성자 매개변수에 memberService, memberRepository를 넣고 실행, 사용해보아도 제대로 빈을 주입받아서 에러가 나지 않습니다. 생성자 주입시 @autowire가 2개 이상일때도 필요한건가에 대해서 궁금합니다.
안녕하세요! 강의 복습을 위해서 토이 프로젝트를 하는 중에 N+1 문제를 어떻게 해결해야 할 지 모르겠어서 질문 드립니다. 먼저, 제가 원하는 출력 결과는 아래와 같습니다. ====== 메뉴 정보 ====== id = 101 메뉴 = 후라이드 가격 = 14000 수량 = 2 ====== 옵션 정보 ====== 옵션 = 눈꽃 치즈볼 4개 가격 = 3500 수량 = 2 옵션 = 치즈볼 4개 가격 = 3000 수량 = 2 ====== 메뉴 정보 ====== id = 22 메뉴 = 후라이드 가격 = 14000 수량 = 1 ====== 옵션 정보 ====== 1. 엔티티 [그림 1]. 엔티티 설계 ※ OrderMenu에서 옵션을 선택하지 않으면 OrderMenu, OrderOption 조인 한 뒤에 OrderOption 조회 시 NullPointerException 발생해서 OrderMenu에 양방향 연관관계 추가 [그림 2]. Join 시 <null> 발생 2. 데이터 [그림 3]. 입력한 데이터 아래와 같은 테스트를 작성했을 때 [그림 4]과 같은 N+1 문제가 발생했습니다. @Test public void 주문메뉴 _ 주문옵션조회 () throws Exception { Long orderId = 100L ; List<OrderMenu> fetch1 = queryFactory .select( orderMenu ) .from( orderMenu ) .where( orderMenu . order . id .eq(orderId)) .fetch() ; for (OrderMenu orderMenu : fetch1) { System. out .println( "====== 메뉴 정보 ======" ) ; System. out .println( "id = " + orderMenu.getId()) ; System. out .println( " 메뉴 = " + orderMenu.getMenu().getName()) ; System. out .println( " 가격 = " + orderMenu.getMenu().getPrice()) ; System. out .println( " 수량 = " + orderMenu.getQuantity()) ; List<OrderOption> orderOptionList = orderMenu.getOrderOption() ; System. out .println( "====== 옵션 정보 ======" ) ; for (OrderOption orderOption : orderOptionList) { System. out .println( " 옵션 = " + orderOption.getOption().getName()) ; System. out .println( " 가격 = " + orderOption.getOption().getPrice()) ; System. out .println( " 수량 = " + orderOption.getQuantity()) ; } } } [그림 4] N + 1 문제 발생 위 문제를 해결하기 위해서 fetch join을 사용해서 OrderMenu와 OrderOption을 한 번에 불러왔지만 OrderMenu의 Menu, OrderOption의 Option은 여전히 Lazy loading이 되었습니다. @Test public void 주문메뉴 _ 주문옵션조회 () throws Exception { Long orderId = 100L ; List<OrderMenu> fetch = queryFactory .selectFrom( orderMenu ) .distinct() .leftJoin( orderMenu . orderOption , orderOption ).fetchJoin() .where( orderMenu . order . id .eq(orderId)) .fetch() ; for (OrderMenu orderMenu : fetch) { System. out .println( "====== 메뉴 정보 ======" ) ; System. out .println( "id = " + orderMenu.getId()) ; System. out .println( " 메뉴 = " + orderMenu.getMenu().getName()) ; System. out .println( " 가격 = " + orderMenu.getMenu().getPrice()) ; System. out .println( " 수량 = " + orderMenu.getQuantity()) ; List<OrderOption> orderOptionList = orderMenu.getOrderOption() ; System. out .println( "====== 옵션 정보 ======" ) ; for (OrderOption orderOption : orderOptionList) { System. out .println( " 옵션 = " + orderOption.getOption().getName()) ; System. out .println( " 가격 = " + orderOption.getOption().getPrice()) ; System. out .println( " 수량 = " + orderOption.getQuantity()) ; } } } 출력 내용 select distinct ordermenu0_.order_menu_id as order_me1_7_0_, orderoptio1_.order_option_id as order_op1_8_1_, ordermenu0_.menu_id as menu_id3_7_0_, ordermenu0_.order_id as order_id4_7_0_, ordermenu0_.quantity as quantity2_7_0_, orderoptio1_.option_id as option_i3_8_1_, orderoptio1_.order_menu_id as order_me4_8_1_, orderoptio1_.quantity as quantity2_8_1_, orderoptio1_.order_menu_id as order_me4_8_0__, orderoptio1_.order_option_id as order_op1_8_0__ from order_menu ordermenu0_ left outer join order_option orderoptio1_ on ordermenu0_.order_menu_id=orderoptio1_.order_menu_id where ordermenu0_.order_id=? ====== 메뉴 정보 ====== id = 101 2021-01-27 15:12:12.595 DEBUG 35340 --- [ main] org.hibernate.SQL : select menu0_.menu_id as menu_id1_3_0_, menu0_.created_date as created_2_3_0_, menu0_.last_modified_date as last_mod3_3_0_, menu0_.menu_category_id as menu_cat8_3_0_, menu0_.name as name4_3_0_, menu0_.price as price5_3_0_, menu0_.image_url as image_ur6_3_0_, menu0_.share_url as share_ur7_3_0_, menucatego1_.menu_category_id as menu_cat1_4_1_, menucatego1_.name as name2_4_1_, menucatego1_.restaurant_id as restaura3_4_1_ from menu menu0_ left outer join menu_category menucatego1_ on menu0_.menu_category_id=menucatego1_.menu_category_id where menu0_.menu_id=? 메뉴 = 후라이드 가격 = 14000 수량 = 2 ====== 옵션 정보 ====== 2021-01-27 15:12:12.604 DEBUG 35340 --- [ main] org.hibernate.SQL : select option0_.option_id as option_i1_6_0_, option0_.name as name2_6_0_, option0_.option_category_id as option_c4_6_0_, option0_.price as price3_6_0_ from options option0_ where option0_.option_id=? 옵션 = 눈꽃 치즈볼 4개 가격 = 3500 수량 = 2 2021-01-27 15:12:12.609 DEBUG 35340 --- [ main] org.hibernate.SQL : select option0_.option_id as option_i1_6_0_, option0_.name as name2_6_0_, option0_.option_category_id as option_c4_6_0_, option0_.price as price3_6_0_ from options option0_ where option0_.option_id=? 옵션 = 치즈볼 4개 가격 = 3000 수량 = 2 ====== 메뉴 정보 ====== id = 22 메뉴 = 후라이드 가격 = 14000 수량 = 1 ====== 옵션 정보 ====== OrderMenu와 OrderOption을 조회할 때, 연관된 Menu와 Option을 한 번에 조회하는 방법이 있을까요? 아니면 엔티티 설계를 변경해야 할까요?
선생님 따라 다했는데 여기서 npm run build 이후.. 라이브 서버로 실행해보보니 컨솔에서 자바스크립트 오류..가 계속 뜹니다. 자꾸 데이터를 불러오지 못하네요.. Uncaught ReferenceError: exports is not defined 따라 가보니 Object.defineProperty(exports, "__esModule", { value: true }); 에서 오류가 생기는것 같습니다.. 혹시 원인을 아시나요? <글자색이 이상하네요 죄송합니다 ㅠ>
StandardScaler 부분 코드를 자세히 읽어보니 get_preprocessed_df 함수를 정의하셨는데, 밑의 코드를 보니 그 함수를 적용하지 않고 바로 card_df를 이용하여 다시 학습을 시키신거 같은데 그렇게 되면 원본 Amount 속성의 값은 변화가 없게 되는거 아닌가요?