[英]Unable to scrape some text out of a hidden container
我已经用python编写了一个脚本,以刮擦位于right-column
楼内的楼层平面图内的某些文本,该文本又位于modal-body
。 但是,当我运行脚本时,它是否显示空白?
单击前的元素( floorplan
和swing
类中的值为null):
<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>
单击后(现在在floorplan
和swing
类中有值):
<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
这是在该地图上启动单击时在框中弹出信息的方式:
如何在该地图上单击以从弹出容器中抓取所需文本?
下面的代码为您提供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())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.