我正在使用python selenium脚本来提取UPS网站的zipcodes之间的运输时间。 " http://ltl.upsfreight.com/shipping/transittimes/transittimes.aspx"
我的代码一直有效,直到我尝试捕获发货时间。我该如何获取价值?以下是来自chrome的html,其值为" 1"我想抓住。
<span id="app_ctl00_ctl01_lblServiceDays" style="font-weight:bold;">1</span>
代码本身:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://ltl.upsfreight.com/shipping/transittimes/transittimes.aspx')
driver.find_element_by_id("app_ctl00_ctl00_OriginZipCodeSelector_OriginZipCodeSelector_txtZip").clear()
driver.find_element_by_id("app_ctl00_ctl00_OriginZipCodeSelector_OriginZipCodeSelector_txtZip").send_keys("07042")
driver.find_element_by_id("app_ctl00_ctl00_DestinationZipCodeSelector_DestinationZipCodeSelector_txtZip").clear()
driver.find_element_by_id("app_ctl00_ctl00_DestinationZipCodeSelector_DestinationZipCodeSelector_txtZip").send_keys("07059")
driver.find_element_by_id("app_ctl00_ctl00_btnSubmit").click()
shiptime = driver.find_element_by_id("app_ctl00_ctl01_lblServiceDays")
print (shiptime)
答案 0 :(得分:1)
您可以尝试在if(!answerDes)
System.out.println("Ascending");
else if(!answerAsc)
System.out.println("Descending");
else {
System.out.println("Not sorted");
}
}
.get_attribute('value')
或.text
取决于您要捕获的字段的类型。
答案 1 :(得分:0)
您的代码对我来说很好。在您的代码中添加一些延迟,如下面的3/5秒ImplicitlyWait,以加载网页HTML DOM。您的代码可以正常工作。
ImplicitlyWait的等效java代码是:
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
如果这有助于您,请告诉我。