Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The goal of my python code is to find the prices of the land on the webpage, and later on also the land area. The code I currently have outputs .webelement in a list, and I want to change it to text (e.g. $131,000).

Current output:

[]
[<selenium.webdriver.remote.webelement.WebElement (session="51532a6317af2be5bfd34c6406d59028", element="65e6939c-3077-4c7a-8dfa-eaa109a0fc0f")>]
[<selenium.webdriver.remote.webelement.WebElement (session="51532a6317af2be5bfd34c6406d59028", element="0221ed59-744e-4e1e-9fc8-5db77a04a2eb")>]

Below is the current python code I am using:

import requests

url = 'https://www.realestate.com.kh/buy/land/?page=1'

r = requests.get(url)

from bs4 import BeautifulSoup

soup = BeautifulSoup(r.content, 'html.parser')

data= []
price = []

driver = webdriver.Chrome()

driver.get('https://www.realestate.com.kh/buy/land/?page=1')

follow_loop = range(0, 14)
for x in follow_loop:
    xpath = '//*[@id="__next"]/main/div[2]/div[1]/div['
    xpath += str(x)
    xpath += ']/article/div[2]/div[1]/div'
    price.append(driver.find_elements_by_xpath(xpath))

for p in price:
    print(p)
driver.close()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
374 views
Welcome To Ask or Share your Answers For Others

1 Answer

for p in price:
    print(p.text)

just call text

if it doesn't bring everything then,

use p.get_attribute("textContent")


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...