홈>
요소의 내용이 아닌 "요소 이름"을 긁어 내려고했습니다. 'data-promo-name'으로 가져 오려고하면 결과는 아래 코드에서 '1 개월 첫 임대료 $1'이어야합니다.
class="ps-properties-property__units__prices col-4 col-md-3" data-promo-id="132" data-promo-name="$1 first month rent">
웹 사이트 : https://www.publicstorage.com/self-storage-mi-ann-arbor/1760?sp=1760|1|Ann%20Arbor|42.28083|-83.74303|0|1 | 1
PFB 코드 :
Sub Element_Name()
Dim ie As New InternetExplorer, ws As Worksheet
Dim element As IHTMLElement
Set ws = ThisWorkbook.Worksheets("Unit Data")
With ie
.Visible = True
.Navigate2 "https://www.publicstorage.com/self-storage-mi-ann-arbor/1760?sp=1760|1|Ann%20Arbor|42.28083|-83.74303|0|1|1"
While .Busy Or .readyState < 4: DoEvents: Wend
Dim listings As Object, listing As Object, headers(), results(), r As Long, c As Long, item As Object
headers = Array("Width", "Length", "Hight/Space Type", "promo", "Reguler Price", "Online Price", "Listing Active", "features", "features1", "features2", "features3", "features4", "features5", "features6")
Set listings = .document.getElementsByClassName("row ps-properties-property__units__row ps-properties-property__units__row__desktop")
ReDim results(1 To listings.Length, 1 To UBound(headers) + 1)
For Each listing In listings
r = r + 1
On Error Resume Next
results(r, 1) = listing.getElementsByClassName("ps-properties-property__units__header")(0).innerText 'Size
'results(r, 4) = listing.getElementsByClassName(Need a code here) 'Promo
results(r, 5) = listing.getElementsByClassName("ps-properties-property__units__prices__old-price")(0).innerText 'Sizet 'Reguler Price
results(r, 6) = listing.getElementsByClassName("ps-properties-property__units__prices__price")(0).innerText 'Online Price
results(r, 7) = listing.getElementsByTagName("ps-properties-property__units__prices col-1 col-md-3")(0).innerText 'Listing Active
results(r, 8) = listing.getElementsByClassName("ps-properties-property__units__feature")(0).innerText 'Features
On Error GoTo 0
Next
ws.Cells(1, 1).Resize(1, UBound(headers) + 1) = headers
ws.Cells(2, 1).Resize(UBound(results, 1), UBound(results, 2)) = results
.Quit
End With
- 답변 # 1
- 답변 # 2
findElement(By.xpath("//div[@class='ps-properties-property__units__prices col-4 col-md-3']")).getAttribute("data-promo-name");
관련 자료
- python - 웹 스크래핑 - 요소 텍스트 데이터 지우기 이름을 찾을 수 없습니다
- r - purrr - : keep을 사용하여 na가있는 목록 요소 이름 추출
- python - 목록의 다른 요소 추출
- python - 마지막 항목없이 사전에서 요소를 추출하는 방법
- vector - `Vec`에서 정확히 하나의 요소를 추출하는 짧은 방법이 있습니까?
- python - Beautiful Soup을 사용하여 h2 요소에서 href 링크 추출
- sql - ID 별 순서가 DESC 인 경우 '스칼라에서 요소를 추출 할 수 없음'
- r - 벡터에서 유사한 요소를 추출하는 방법은 무엇입니까?
- java - 두 배열 목록을 비교하고 두 배열 배열에서 공통적이지 않은 세 번째 배열 목록의 요소를 추출하는 방법
- 스칼라 XML은 쉼표 구분 기호로 요소를 추출합니다
관련 질문
- javascript : Excel 파일을 HTML로 내보내기 [바람직하게는 VBA를 통해]
- excel : VBA를 사용하여 text.file의 숫자 변경
- Excel에서 입력 시트 만들기 및 입력을 다른 시트의 계산기에 복사하고 세 번째 시트에 보관하는 이벤트
- excel : 범위를 반복하여 수식을 복사하여 명명된 범위 만들기
- Excel의 리본 변경 사항을 현재 통합 문서에 고유하게 만드는 방법이 있습니까?
- vb.net : Excel Paste이미지로 붙여넣기 특수 기능
- c# : Excel에서 검색할 수 있는 asp.net API를 통해 QR 이미지 제공
- Excel -셀이 특정 날짜와 동일한 경우 동일한 행에서 여러 셀 복사
- excel : 세포 비교
- excel : COUNTIF 또는 VBA를 사용하여 3개의 열을 살펴보고 행의 값을 계산하려면 어떻게 해야 합니까?
노드를 분리 한 다음 getAttribute 함수를 사용해야합니다
html이 다르게 나타납니다.
한 줄을 사용한 예는
전체 코드 :