경매사이트 크롤링할 때 로그인해야만 보이는 정보를 가져오고 싶어요
안녕하세요
유튜브를 통해서 오빠두 엑셀을 처음 접하고 열심히 vba 공부해서 잘 활용하고 있습니다.
네이버 부동산 크롤링하는 편을 보고 공부해서 경매사이트의 물건 정보를 크롤링하는 코드를 만들었는데요
문제는 낙찰가를 로그인한 회원들에게만 제공하기 때문에 낙찰가 정보를 가져오면 🔒 이 아이콘으로 나오네요.
로그인 안한 상태에서 Export해서 보면 ??로 보이고, 로그인 한 후에 보면 가져와야할 정보가 정상적으로 표시되네요.
---------------------------로그인 했을 때----------------------------
<td>
낙찰 </td>
</tr>
<tr>
<td colspan="4"><div><span class="color-warm-pink">낙찰 <strong>125,199,000</strong>원</span> (<span class="color-warm-pink">76%</span>)</div><div>(응찰 : 4명 / 낙찰자 : 박경진외1인 / 차순위 : 123,100,000)</div><div>매각결정기일 : 2018.07.12 - 매각허가결정</div><div>대금지급기한 : 2018.08.10</div><div>대금납부 : 2018.07.30 / 배당기일 : 2018.08.30</div><div><span class="color-warm-pink">배당종결 : 2018.08.30</span></div></td>
</tr>
---------------------------로그인 안했을 때----------------------------
<td>
낙찰 </td>
</tr>
<tr>
<td colspan="4"><div><span class="color-warm-pink">낙찰 <strong>🔒</strong>원</span> (<span class="color-warm-pink">24%</span>)</div><div>(응찰 : 1명 / 낙찰자 : <span id="nakchalja">박OO</span>)</div><div>매각결정기일 : 2022.04.07 - 매각허가결정</div><div>대금지급기한 : 2022.05.17</div><div>대금납부 : 2022.04.26 / 배당기일 : 2022.05.24</div></td>
</tr>
vba코드로 자동 로그인한 후에 페이지에 접근해서 하도록 실행도 해봤는데 여전히 자물쇠로 나오네요 ㅠㅠ
방법이 없을까요?
번호 | 카테고리 | 제목 | 작성자 | 작성일 | 추천 | 조회 |
[🏆 진짜쓰는 실무엑셀 스터디] 1기 - 우수 졸업생 및 후기, 축하합니다! (8)
![]() ![]() |
![]() ![]() |
2022.04.30 | 10 | 1284 | ||
공지사항 | 함수/공식 |
⭐ [더 나은 커뮤니티 문화를 위한 Q&A 글 작성 규칙] ⭐
(65)
오빠두엑셀
|
2021.10.28
|
추천 81
|
조회 4610
|
![]() ![]() |
2021.10.28 | 81 | 4610 |
34492 | VBA |
New 엑셀에 드래그 앤 드롭으로 그림파일 삽입
(1)
![]() |
![]() |
15:55 | 0 | 5 |
34477 | 문서서식 |
New 수식 복사 질문드려요.. ㅠㅠ 불금 퇴근하고싶습니다...
![]() ![]() |
![]() |
2022.05.27 | 0 | 36 |
34473 | VBA |
New 비고란에서 휴대폰번호 추출하기에 관해 문의드립니다.
![]() ![]() |
![]() |
2022.05.27 | 0 | 31 |
34472 | 기능/도구 |
New 스핀단추에서 증분변경시 0.1 씩 증감할려면 어떻게 해야 할까요?
(1)
![]() |
![]() |
2022.05.27 | 0 | 26 |
34471 | 함수/공식 |
New 조건부서식 중복 2개이상 및 2개일때 서식좀 봐주세요 궁금합니다.
![]() ![]() |
![]() |
2022.05.27 | 0 | 37 |
34469 | 문서서식 |
New 표의 행렬 변경
![]() ![]() |
![]() |
2022.05.27 | 0 | 34 |
34465 | 차트/그래프 |
New 간트차트에 오늘 표시하는 방법 질문드려요
![]() |
![]() |
2022.05.27 | 0 | 29 |
34464 | VBA |
New Vba로 수식을 입력하려는데 오류가 납니다.
(3)
![]() |
![]() |
2022.05.27 | 0 | 33 |
34451 | 함수/공식 |
New 제품별 코드 중복/단독 확인함수
![]() ![]() |
![]() |
2022.05.27 | -1 | 47 |
34450 | VBA |
New VBA를 활용한 최단거리 계산(Pathfinder,카카오맵)
![]() ![]() |
![]() |
2022.05.27 | 0 | 33 |
34448 | 함수/공식 |
New countif 다양한 조건으로 만들고 싶어요~
![]() ![]() |
![]() |
2022.05.27 | 0 | 45 |
34444 | 기능/도구 |
New 엑셀 빠른 도구 모음에 있는 '조명'이 무슨 기능인지 아시는분 계신가요?
![]() |
![]() |
2022.05.26 | 0 | 45 |
34440 | 함수/공식 |
New 고객 리텐션, 접속 일수에 맞춰 데이터를 합산하는 함수/VBA 문의!
![]() ![]() |
![]() |
2022.05.26 | 0 | 22 |
34439 | 차트/그래프 |
New 체크박스 선택에 따라 값이 바뀌는 차트의 데이터레이블 표시 문제 관련
![]() ![]() |
![]() |
2022.05.26 | 0 | 25 |
34437 | 함수/공식 |
New 국가만 찾아 올련면
![]() ![]() |
![]() |
2022.05.26 | 0 | 40 |
34433 | 함수/공식 |
New 함수관련 질문있습니다.
![]() |
![]() |
2022.05.26 | 0 | 31 |
34427 | 함수/공식 |
New 특정 공휴일 제외 후 2달 뒤 날짜를 구할수 있는 함수 식이 있을까요?
(1)
![]() |
![]() |
2022.05.26 | 0 | 42 |
34417 | 피벗테이블 |
New 피벗테이블 외부 데이터 참조 후 새로고침 할 때 자꾸 암호를 입력하라고 떠요..
(2)
답변완료
![]() |
![]() |
2022.05.26 | 0 | 35 |
34416 | 함수/공식 |
New 날짜/시간 차이를 구하려면 어떻게 하면 좋을까요?
![]() ![]() |
![]() |
2022.05.26 | 0 | 41 |
34415 | VBA |
New VBA코드로 자동채우기 할때 유동범위는 어떻게 하나요
![]() ![]() |
![]() |
2022.05.26 | 1 | 40 |
34414 | 함수/공식 |
New 금지어 삭제하는 함수 (특정텍스트 범위내의 값을 제거 후 값 불러오기)
![]() ![]() |
![]() |
2022.05.26 | 0 | 42 |
34406 | 함수/공식 |
New sum 함수 오류?
![]() ![]() |
![]() |
2022.05.25 | 0 | 52 |
34405 | VBA |
New 중복데이터가 많은데 맨 위에 있는 행의 데이터만 남길 수 있는 방법이 있을까요?
![]() ![]() |
![]() |
2022.05.25 | 0 | 67 |
34402 | VBA |
vba 특정문자 입력시 현재시간 구동 관련
![]() ![]() |
![]() |
2022.05.25 | 0 | 46 |
34400 | 함수/공식 |
다른 셀 값 참조시 결과값이 0으로만 나오는 현상 문의
![]() ![]() |
![]() |
2022.05.25 | 0 | 46 |
34395 | VBA |
조건이 맞을 경우 범위데이터 이동 or 복사,삭제 문의
![]() ![]() |
![]() |
2022.05.25 | 0 | 54 |
34392 | 함수/공식 |
다른 파일을 참조하여 합계를 구하는데, 그 참조 파일의 이름이 바뀐다면?
(1)
![]() |
![]() |
2022.05.25 | 0 | 35 |
34391 | 기능/도구 |
F1 키 누르면 나오는 도움말 끄는 단축키는 없나요?
(5)
![]() |
![]() |
2022.05.25 | 0 | 47 |
34390 | 함수/공식 |
셀이 빈 경우 텍스트조인이 실행되지 않도록 하는 방법
![]() ![]() |
![]() |
2022.05.25 | 0 | 58 |
34387 | VBA |
개별공시지가조회 셀레니움
![]() ![]() |
![]() |
2022.05.25 | 0 | 46 |
말씀해주신 증상으로만 봐서는 로그인 후 세션이 유지되지 않은 상태로 페이지를 크롤링해오는것으로 보입니다.
쿠키 등을 이용하여 로그인 세션을 유지해줘야 하는데, vba로 로그인하시는 과정을 어떤 코드로 구현하셨는지 알려주시면
다른분들이 확인 및 답변에 도움이 될 듯 합니다.
@간소 님 로그인 세션을 유지해줘야하는 군요 ㅠㅠ
부끄럽지만 코드 전문올립니다 ㅠㅠ
----------------------------------------로그인 없이 경매 물건 정보 긁어오는 코드-------------------------------------
Sub caseCrawl(wsRowsStart As Integer, wsRowsEnd As Integer)
Dim ws1 As Worksheet: Set ws1 = Sheets("리소스")
Dim URL As String
Dim URL_Login As String
Dim htmlResult As Object '<- GetHTTP 명령문의 결과값 ... >> HTML 문서
Dim strResult As String '<-htmlResult 에서 받아온 HTML 문자열
Dim Cookie As String
Dim auctionId As String '두인경매 사건ID
Dim caseNum As String ' 사건번호
Dim addr As String '주소
Dim buildingArea As String '건물 면적
Dim auctionDate As String '매각기일
Dim buildingType As String '물건종류
Dim landArea As String '대지권
Dim casePrice As String '감정가
Dim lowPrice As String '최저입찰가
Dim depositPrice As String '입찰보증금
Dim bidderCount As String '응찰자수
Dim highestBidPrice As String '낙찰가
Dim secondBidPrice As String '차순위 입찰가
Dim state As String '상태
Dim vAuctionDate As Variant '입찰기일을 넣을 배열
Dim vAuctionDate1 As Variant '입찰기일을 넣을 배열
Dim vState1 As Variant '상태를 넣을 배열
Dim vState2 As Variant '상태를 넣을 배열
Dim sAuctionId As Byte: sAuctionId = [소스_두인경매ID]
Dim sBuildingType As Byte: sBuildingType = [소스_물건종류]
Dim sAddr As Byte: sAddr = [소스_소재지]
Dim sArea As Byte: sArea = [소스_면적]
Dim sAuctionDate As Byte: sAuctionDate = [소스_매각기일]
Dim sCaseNum As Byte: sCaseNum = [소스_사건번호]
Dim sCasePrice As Byte: sCasePrice = [소스_감정가]
Dim sLowPrice As Byte: sLowPrice = [소스_최저입찰가]
Dim sDepositPrice As Byte: sDepositPrice = [소스_입찰보증금]
Dim sState As Byte: sState = [소스_상태]
Dim sBidderCount As Byte: sBidderCount = [소스_응찰자]
Dim sHighestBidPrice As Byte: sHighestBidPrice = [소스_낙찰가]
Dim sSecondBidPrice As Byte: sSecondBidPrice = [소스_차순위낙찰가]
Dim wsRows As Integer
'Dim wsRowsStart As Integer: wsRowsStart = 343
'Dim wsRowsEnd As Integer: wsRowsEnd = 343 'ws1.[F4].CurrentRegion.Rows.count + 3
Application.ScreenUpdating = False '이미지가 삽입될 때 속도 저하를 방지하기 위해서 함수 화면 업데이트를 off
Application.EnableEvents = False '수식이 변경될 때 더 빠르세 실행하기위함.
'로그인
For wsRows = wsRowsStart To wsRowsEnd
auctionId = ws1.Cells(wsRows, sAuctionId)
URL = "https://www.dooinauction.com/auction/search/?auction_id=" & auctionId '두인경매
'URL_Login = "https://www.dooinauction.com/login/?redirect_to=https%3A%2F%2Fwww.dooinauction.com%2Fauction%2Fsearch%2F%3Fauction_id%3D" & auctionId
Set htmlResult = Nothing
Set htmlResult = GetHttp(URL, , , , True)
'On Error Resume Next
strResult = htmlResult.body.innerHTML
'Debug.Print strResult
'ExportText strResult
'사건번호
If InStr(strResult, "<!-- //관련 물건번호 탭 -->") > 0 Then
caseNum = Splitter(strResult, "<!-- //관련 물건번호 탭 -->", "</div>")
caseNum = Splitter(caseNum, "<div class=""list-cell color-nice-blue"">")
Sheet1.Cells(wsRows, sCaseNum) = caseNum
Else:
caseNum = Splitter(strResult, "<!-- 상품 정보 -->", "</div>")
'Debug.Print caseNum
caseNum = Splitter(caseNum, "<div class=""list-cell color-nice-blue"">")
'Debug.Print caseNum
Sheet1.Cells(wsRows, sCaseNum) = caseNum
End If
'물건종류
buildingType = Splitter(strResult, "<th><strong>물건종류</strong></th>", "</td>")
buildingType = Splitter(buildingType, "<td class=""text-align-left"">")
buildingType = Replace(buildingType, Chr(10), "")
Sheet1.Cells(wsRows, sBuildingType) = Trim(buildingType)
'주소
addr = Splitter(strResult, "<th><strong>소재지</strong></th>", "</strong></td>")
addr = Splitter(addr, "<td class=""text-align-left"" colspan=""5""><strong>", "</strong>")
'도로명 주소가 포함되어있으면 삭제하는 코드
If Right(addr, 1) = "]" Then
Dim l As Integer: l = InStr(addr, " [")
addr = Left(addr, l - 2)
End If
addr = Replace(addr, "경기", "경기도")
addr = Replace(addr, "충남", "충청남도")
addr = Replace(addr, "충북", "충청북도")
addr = Replace(addr, "경남", "경상남도")
addr = Replace(addr, "경북", "경상북도")
addr = Replace(addr, "전남", "전라남도")
addr = Replace(addr, "전북", "전라북도")
Sheet1.Cells(wsRows, sAddr) = addr
'건물 면적
buildingArea = Splitter(strResult, "<th><strong>건물면적</strong></th>", "</strong></td>")
buildingArea = Splitter(buildingArea, "<td class=""text-align-left"">", "</td>")
landArea = Splitter(strResult, "<th><strong>대지권</strong></th>", "</strong></td>")
landArea = Splitter(landArea, "<td class=""text-align-left"">", "</td>")
ws1.Cells(wsRows, sArea) = "건물 " & buildingArea & " / 대지권 " & landArea
'매각기일
auctionDate = Splitter(strResult, "<th>상태</th>", "</tbody>")
If InStr(auctionDate, "차") Then
vAuctionDate = Split(auctionDate, "차</td>")
'Debug.Print auctionDate
Dim z As Integer
For z = LBound(vAuctionDate) + 1 To UBound(vAuctionDate)
'Debug.Print vAuctionDate(z)
auctionDate = Splitter(vAuctionDate(z), "<td>", "</td>")
Next
ws1.Cells(wsRows, sAuctionDate) = auctionDate
ElseIf InStr(auctionDate, "종국결과") Then
vAuctionDate = Split(auctionDate, "종국결과</td>")
'Debug.Print auctionDate
For z = LBound(vAuctionDate) + 1 To UBound(vAuctionDate)
'Debug.Print vAuctionDate(z)
auctionDate = Splitter(vAuctionDate(z), "<td>", "</td>")
Next
ws1.Cells(wsRows, sAuctionDate) = auctionDate
Else
vAuctionDate1 = Split(auctionDate, "입찰변경</td>")
'Debug.Print auctionDate
'Dim z As Integer
For z = LBound(vAuctionDate1) + 1 To UBound(vAuctionDate1)
'Debug.Print vAuctionDate1(z)
auctionDate = Splitter(vAuctionDate1(z), "<td>", "</td>")
Next
ws1.Cells(wsRows, sAuctionDate) = auctionDate
End If
' vAuctionDate = Split(auctionDate, "차</td>")
' Debug.Print auctionDate
' Dim z As Integer
'
' For z = LBound(vAuctionDate) + 1 To UBound(vAuctionDate)
' Debug.Print vAuctionDate(z)
' auctionDate = Splitter(vAuctionDate(z), "<td>", "</td>")
'
' Next
'
' ws1.Cells(wsRows, sAuctionDate) = auctionDate
'감정가
casePrice = Splitter(strResult, "<th><strong>감정가</strong></th>", "</strong></td>")
casePrice = Splitter(casePrice, "<td class=""text-align-right""><strong class=""color-black"">", "원")
ws1.Cells(wsRows, sCasePrice) = casePrice
'최저입찰가
lowPrice = Splitter(strResult, "<th><strong>최저가</strong></th>", "원</strong></td>")
lowPrice = Splitter(strResult, "<td class=""text-align-right""><strong class=""color-cornflower"">", "원")
ws1.Cells(wsRows, sLowPrice) = lowPrice
'입찰 보증금
depositPrice = Splitter(strResult, "<th><strong>입찰보증금</strong></th>", "원</strong></td>")
depositPrice = Splitter(depositPrice, "<td class=""text-align-right""><strong class=""color-black"">", "원")
ws1.Cells(wsRows, sDepositPrice) = depositPrice
'상태
state = Splitter(strResult, "<th>상태</th>", "</tbody>")
state = Splitter(state, "<tr class=""point"">", "</tr>")
'Debug.Print state
vState1 = Split(state, Chr(10))
z = 0 'For문에 사용할 z값 초기화
For z = LBound(vState1) + 1 To UBound(vState1) - 1
state = Trim(Replace(vState1(z), "</td>", ""))
state = Trim(Replace(state, Chr(9), ""))
Next
If InStr(state, "변경") Then
state = Splitter(state, "<span class=""color-cornflower"">", "</span>")
ws1.Cells(wsRows, sState) = state
End If
ws1.Cells(wsRows, sState) = state
'낙찰가
' If InStr(state, "낙찰") Then
' highestBidPrice = Splitter(strResult, "낙찰 </td>", "매각결정기일")
' highestBidPrice = Splitter(highestBidPrice, "<strong>", "</strong>")
' End If
' ws1.Cells(wsRows, sHighestBidPrice) = highestBidPrice
'디버그용
Debug.Print "Line: " & wsRows
Next
'추가된 열부터 가져오는 기능.
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
---------------------------로그인 하는 코드----------------------------------
Sub DooinLogin(LoginID As String, LoginPW As String)
'// 네이버 자동 로그인 명령문 시작
Dim MyBrowser As InternetExplorer
Dim MyURL As String
Dim HTMLDoc As HTMLDocument
Dim txtID As IHTMLElement
Dim txtPW As IHTMLElement
Dim btnLogin As IHTMLElement
Dim strResult As String
Dim Cookie As String
'On Error GoTo Err_Clear
MyURL = "https://www.dooinauction.com/login/"
Set htmlResult = Nothing
Set htmlResult = GetHttp(MyURL, , , , True)
'On Error Resume Next
strResult = htmlResult.body.innerHTML
'Debug.Print strResult
'ExportText strResult
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
MyBrowser.Visible = True
MyBrowser.navigate MyURL
Wait_Browser MyBrowser
Set HTMLDoc = MyBrowser.document
'ID 입력
For Each txtID In HTMLDoc.getElementsByClassName("form-control")
If txtID.Name = "log" Then txtID.Value = LoginID: Exit For
Next
'PW 입력
For Each txtPW In HTMLDoc.getElementsByClassName("form-control is-invalid")
If txtPW.Name = "pwd" Then txtPW.Value = LoginPW: Exit For
Next
For Each btnLogin In HTMLDoc.getElementsByClassName("btn w-100 btn-cornflower btn-vlg btn-login")
If btnLogin.className = "btn w-100 btn-cornflower btn-vlg btn-login" Then btnLogin.Click: Exit For
Next
'추가된 열부터 가져오는 기능.
Application.ScreenUpdating = True
Application.EnableEvents = True
Exit Sub
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub