无法从隐藏内容中刮出一些文本

2024-10-03 06:31:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经用python编写了一个脚本来抓取类floorplan中的某个文本,该类位于right-column中,该类位于modal-body中。但是,当我运行脚本时,它会给出空白输出?你知道吗

link to that site

单击前的元素(值在floorplanswing类中为空):

<div class="right-column">
    <div class="field" ng-show="selectedLot.Name !== ''">
        <div class="label">Home Design:</div>
        <div class="floorplan value ng-binding"></div>
        <hr>
    </div>
    <div class="field" ng-show="selectedLot.ShortDescription !== ''">
        <div class="label">Elevation:</div>
        <div class="swing value ng-binding"></div>
        <hr>
    </div>
    <div class="field" ng-show="selectedLot.Swing !== ''">
        <div class="label">Swing:</div>
        <div class="swing value ng-binding"></div>
        <hr>
    </div>
</div>

单击后(值现在位于floorplanswing类中):

<div class="right-column">
    <div class="field" ng-show="selectedLot.Name !== ''">
        <div class="label">Home Design:</div>
        <div class="floorplan value ng-binding">Delaware</div>
        <hr>
    </div>
    <div class="field" ng-show="selectedLot.ShortDescription !== ''">
        <div class="label">Elevation:</div>
        <div class="swing value ng-binding">TRA</div>
        <hr>
    </div>
    <div class="field" ng-show="selectedLot.Swing !== ''">
        <div class="label">Swing:</div>
        <div class="swing value ng-binding">Garage Right</div>
        <hr>
    </div>
</div>

到目前为止,我已经尝试了(can't make my script click on that image to reveal the data I'm after):

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

def collect_links(link):
    driver.get(link)
    wait.until(EC.invisibility_of_element_located((By.CSS_SELECTOR,"path#ip-loader-circle")))
    item = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,".modal-body .right-column .floorplan")))
    print(item.get_attribute("innerHTML"))

if __name__ == '__main__':
    url = "https://khovsecure.ml3ds-cloud.com/index.html?_ga=2.181197287.1174152084.1550480313-902396065.1550480313#/lotmap/43935"
    driver = webdriver.Chrome()
    wait = WebDriverWait(driver,20)
    collect_links(url)
    driver.quit()

预期产量:

Delaware

这就是当点击地图时,信息是如何在框中弹出的:

enter image description here

How can I make a click on that map to scrape the desired text from the pop up container?


Tags: fromdivfieldvalueseleniumshowhrng
1条回答
网友
1楼 · 发布于 2024-10-03 06:31:01

下面的代码提供json格式的所有数据:

import requests

if __name__ == '__main__':
    headers = {
        'fullurl': 'https://khovsecure.ml3ds-cloud.com/index.html?_ga=2.181197287.1174152084.1550480313-902396065.1550480313#/lotmap/43935',
    }
    response = requests.get('https://khovsecure.ml3ds-cloud.com/resources/data/CommunityData/khovsecure.ml3ds-cloud.com', headers=headers)
    print(response.json())

相关问题 更多 >