how would i get the date from reviews not replies?
current code is:
date_ref = driver.find_elements(By.TAG_NAME, "time")
but that gets both date from reviews and replies
Reviews
<time datetime="2022-02-03T06:11:02.000Z" data-service-review-date-time-ago="true" title="Thursday, 3 February 2022, 05:11:02 pm">3 Feb 2022</time>
Replies
<time datetime="2022-02-07T03:31:52.999Z"
data-service-review-business-reply-date-time-ago="true" title="Monday, 7 February 2022, 02:31:52 pm">7 Feb 2022</time>
how can i grab the date from the reviews but not the replies?
thanks
CodePudding user response:
You are using TAG_NAME
which is the same for both reviews and replies. Therefore results in 2 nodes
, (could be many however that depends on your HTML-DOM
).
If you want to differentiate the nodes, I see that data-service-review-date-time-ago
attribute is unique for review.
Hence changing that to either CSS/XPATH would get the job done.
CSS: time[data-service-review-date-time-ago]
XPATH: //time[@data-service-review-date-time-ago]
You can call them using driver.find_element(By.XPATH, "//time[@data-service-review-date-time-ago]")
or driver.find_element(By.CSS_SELECTOR, "time[data-service-review-date-time-ago]")
etc.
Also, note that you are using find_elements
which would return a list of web elements, may be you wanted to use find_element
if you were targeting the first node.