无法在Python 2.7中打印

时间:2015-06-30 23:51:28

标签: python python-2.7 selenium unicode selenium-webdriver

所以这是我正在运行的代码:

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
current_price = []
def page_is_loaded(driver):
    return driver.find_element_by_tag_name("body") != None
driver = webdriver.Firefox()
driver.get("https://marketsworld.com/")
wait = WebDriverWait(driver, 10)
wait.until(page_is_loaded)
email_field = driver.find_element_by_id("user_login_email")
email_field.send_keys("myusername")
password_field = driver.find_element_by_id("user_login_password")
password_field.send_keys("mypass")
password_field.send_keys(Keys.RETURN)
element = driver.find_element_by_class_name("market_value")
instance = element.text
print instance

当我尝试打印instance时,我得到的输出是

/usr/bin/python2.7 /home/phuhzy/PycharmProjects/pychar_test/test2.py

(I don't get any output here. Only a blank line.)

Process finished with exit code 0

不确定为什么我输出一个空行。如果我将其打印为print type(instance),我会将unicode作为类型返回。

1 个答案:

答案 0 :(得分:0)

我假设element.text为空或None并且没有任何内容可供打印。

不知道实际数据是不可能的。

您可以通过

进行测试
if not instance:
    print "No data"