Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 刮取可点击链接或xpath_Python_Selenium_Xpath_Web Scraping_Linked List - Fatal编程技术网

Python 刮取可点击链接或xpath

Python 刮取可点击链接或xpath,python,selenium,xpath,web-scraping,linked-list,Python,Selenium,Xpath,Web Scraping,Linked List,我在web应用程序中有此html树: 我已经把所有联赛名称的文字都删掉了 但我还需要一个XPATH或任何指示符,这样我就可以告诉selenium:如果我在我的GUI中从e。G一个下拉菜单,然后使用相应的xpath在web应用程序中选择正确的联盟 我不知道如何从该树中提取一个XPATCH,也不知道如何使用任何其他可用于我的场景的解决方案 你知道我该怎么解决这个问题吗 如果我尝试提取'href',它只打印“无” 这是我目前的代码: def scrape_test(): leagues =

我在web应用程序中有此html树:

我已经把所有联赛名称的文字都删掉了

但我还需要一个XPATH或任何指示符,这样我就可以告诉selenium:如果我在我的GUI中从e。G一个下拉菜单,然后使用相应的xpath在web应用程序中选择正确的联盟

我不知道如何从该树中提取一个XPATCH,也不知道如何使用任何其他可用于我的场景的解决方案

你知道我该怎么解决这个问题吗

如果我尝试提取'href',它只打印“无”

这是我目前的代码:

def scrape_test():

    leagues = []
    #click the dropdown menue to open the folder with all the leagues
    league_dropdown_menu = driver.find_element_by_xpath('/html/body/main/section/section/div[2]/div/div[2]/div/div[1]/div[1]/div[7]/div')
    league_dropdown_menu.click()
    time.sleep(1)
    
#get all league names as text
    scrape_leagues = driver.find_elements_by_xpath("//li[@class='with-icon' and contains(text(), '')]")
    for league in scrape_leagues:
        leagues.append(league.text)
    print('\n')

# HERE I NEED HELP! - I try to get a link/xpath for each corresponding league to use later with selenium
    scrape_leagues_xpath = driver.find_elements_by_xpath("//li[@class='with-icon']")
    for xpath in scrape_leagues_xpath:
        leagues.append(xpath.get_attribute('xpath')) #neither xpath, text, href is working here

    print(leagues)

li
节点没有
text
href
xpath
(我认为它不是有效的HTML属性)。您可以刮取和解析
@style

尝试使用此方法提取背景图像URL

leagues.append(xpath.get_attribute('style').strip('background-image:url("').rstrip('");'))

添加html作为文章的一部分,而不是我所需要的图片!谢谢