2013-02-16 34 views
0

如何使用python web驱动程序获取web表中的特定行&列值。我一直在尝试,但我无法得到它。请任何一个给我想法,我们如何获得行&列值。在这里我的代码使用python web驱动程序获取web表中的行和列值

start="//*[@id='p1']/div/table/tbody/tr[" 
end= str(i)+ "]/td[1]/a" 
row1=driver.find_element_by_xpath(start + end) 
print row1.text 

回答

2

试试这个,它在我的系统工作正常:

driver = webdriver.Firefox() 
driver.get("http://www.flipkart.com/programming-python-4th-e-d/p/itmczzj4gpfrr6bs?pid=9789350232873&icmpid=reco_pp_hSame_book_1") 
data=[] 
for tr in driver.find_elements_by_xpath('//table[@class="mprod-similar-prod-table"]//tr'): 
    tds=tr.find_elements_by_tag_name('td') 
    if tds: 
    data= [td.text for td in tds] 
print "3730" in data[2] #or whatever is the current price 
相关问题