本文整理汇总了Python中selenium.webdriver.common.by.By.xpath方法的典型用法代码示例。如果您正苦于以下问题:Python By.xpath方法的具体用法?Python By.xpath怎么用?Python By.xpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.common.by.By
的用法示例。
在下文中一共展示了By.xpath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_parent
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import xpath [as 别名]
def get_parent(self):
return self.web_element.find_element(By.xpath('..'))
示例2: get_param
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import xpath [as 别名]
= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'
ghost = webdriver.PhantomJS(executable_path='E:/software/phantomjs-2.1.1-windows/bin/phantomjs.exe')
def get_param( driver, url ):
driver.get(url)
total_txt = driver.find_element_by_id("total").text
#try:
return total_txt
if __name__ == '__main__':
cid = 566921
url_address = "https://iknow.jp/courses/%d"%cid
#total = get_param(ghost,url_address)
# f = open("record.txt","wt+",encoding="UTF-8")
#ofile_name = "record_%d.txt"%cid
#ofile = codecs.open(ofile_name, "w", "utf-8")
voclist = ghost.findElements(By.xpath("//li"))
for i in voclist:
print(i)
#for j in range(0, total):
current_page = ghost.find_element_by_css_selector('.items').text
print("current page:" + current_page)
k = 0
# get_transaction_from_page(ofile, ghost, int(current_page), total)
ghost.close()
#ofile.close()
示例3: get_items
# 需要导入模块: from selenium.webdriver.common.by import By [as 别名]
# 或者: from selenium.webdriver.common.by.By import xpath [as 别名]
def get_items(self) -> list:
li_list = self.web_element.find_elements(By.xpath('/li'))
return DomElementFactory.create_dom_element_list(li_list)