Last active
August 5, 2024 07:22
-
-
Save JinKwonJeon/f842865b6a9b528b966f1fa0955c657d to your computer and use it in GitHub Desktop.
NaverShoppingKeywords 함수 (PowerQuery M)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (Keywords as text) => | |
| let | |
| // Step 1: 네이버 쇼핑 메인 페이지에서 키워드 검색 결과를 바이너리 형식으로 가져오기 | |
| NShoppingMain = Web.BrowserContents("https://search.shopping.naver.com/search/all?query="&Keywords) | |
| // Step 2: 'initialState":{"products' 문자열의 위치 찾기 | |
| InitStatePos = Text.PositionOf(NShoppingMain, "initialState"":{""products"""), | |
| // Step 3: 'mainFilters":' 문자열의 위치 찾기 | |
| MainFilterPos = Text.PositionOf(NShoppingMain, """mainFilters"":"), | |
| // Step 4: 'initialState'와 'mainFilters' 사이의 텍스트를 JSON 형식으로 변환 | |
| TextProductList = Json.Document(Text.Middle(NShoppingMain, InitStatePos + 14, MainFilterPos - InitStatePos - 16) & "}}"), | |
| // Step 5: products 리스트 추출 | |
| productslist = TextProductList[products][list], | |
| // Step 6: 리스트를 테이블 형식으로 변환 | |
| ConvertToTable = Table.FromList(productslist, Splitter.SplitByNothing(), null, null, ExtraValues.Error), | |
| // Step 7: 'item' 열 확장 | |
| ExpandTable = Table.ExpandRecordColumn(ConvertToTable, "Column1", {"item"}, {"item"}), | |
| // Step 8: 'item' 열에서 'productTitle' 열 추출 | |
| GetData = Table.ExpandRecordColumn(ExpandTable, "item", {"productTitle"}, {"productTitle"}), | |
| // Step 9: 'productTitle' 열을 공백으로 구분하여 여러 열로 분할한 후, 모든 열을 단일 '키워드' 열로 병합 | |
| SplitBySpace = Table.UnpivotOtherColumns(Table.SplitColumn(GetData, "productTitle", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), 50), {}, "Temp", "키워드"), | |
| // Step 10: '키워드' 열을 기준으로 그룹화하여 각 키워드의 빈도수 계산 | |
| GetKeywordCount = Table.Group(Table.SelectColumns(SplitBySpace,{"키워드"}), {"키워드"}, {{"개수", each Table.RowCount(_), Int64.Type}}), | |
| // Step 11: 키워드 빈도수를 내림차순으로 정렬 | |
| NaverShoppingKeywords = Table.Sort(GetKeywordCount,{{"개수", Order.Descending}}) | |
| in | |
| NaverShoppingKeywords |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
2024-08-05 / WebBrowserContents 함수로 웹 데이터 호출 방식 변경