我正在尝试在此页的第二列中获取产品详细信息:
我正在使用以下xpath
://*[@id="productDetailsTable"]/tbody/tr/td/div[2]/ul/li/text()
代码:
if self.hasXpath('//*[@id="productDetailsTable"]/tbody/tr/td/div/ul/li/b'):
prod_info_dt = []
prod_info_dd = []
prod_info_dt_list = self.browser.find_elements_by_xpath('//*[@id="productDetailsTable"]/tbody/tr/td/div/ul/li/b')
prod_info_list_count = len(prod_info_dt_list)
for curr_prod_dt_info in prod_info_dt_list:
prod_info_dt.append(curr_prod_dt_info.get_attribute('innerHTML').encode('ascii','ignore').strip().replace('.','_'))
prod_info_dd_list = self.browser.find_elements_by_xpath('//*[@id="productDetailsTable"]/tbody/tr/td/div[2]/ul/li/text')
for curr_prod_dd_info in prod_info_dd_list:
if curr_prod_dd_info.get_attribute('innerHTML').encode('ascii','ignore').strip()=='<i class="fi-x"></i>':
prod_info_dd.append("No")
elif curr_prod_dd_info.get_attribute('innerHTML').encode('ascii','ignore').strip()=='<i class="fi-check"></i>':
prod_info_dd.append("Yes")
else:
prod_info_dd.append(curr_prod_dd_info.get_attribute('innerHTML').encode('ascii','ignore').strip())
for x in range(prod_info_list_count):
product_dict[prod_info_dt[x]] = prod_info_dd[x]
答案 0 :(得分:0)
我不确定您要看哪个值。如果您要照管产品说明,则应该使用xpath
。
elements=driver.find_elements_by_xpath("//div[@id='feature-bullets']/ul/li/span")
proddesc=[]
for ele in elements:
print(ele.text)
proddesc.append(ele.text)
print(proddesc)