使用Python使用Selenium查找网页内的文本

使用Python使用Selenium查找网页内的文本,python,selenium,Python,Selenium,我正在尝试使用Python在Selenium的网页上查找电话号码。如果电话号码有href标签,则我的代码工作正常,但如果标签丢失(表示电话号码不可单击),则代码不工作 步骤: URL = driver.get("url.com") try: element = driver.find_element_by_xpath("//*[text()='(123) 111-1234']") if elemen

我正在尝试使用Python在Selenium的网页上查找电话号码。如果电话号码有href标签,则我的代码工作正常,但如果标签丢失(表示电话号码不可单击),则代码不工作

步骤:

    URL = driver.get("url.com")
    
    try:
        element = driver.find_element_by_xpath("//*[text()='(123) 111-1234']")
        if element.is_displayed():
            print("Phone number found")
    
                
    except NoSuchElementException:
        print("Phone number not found")
  • 检查所有网站页面
  • 查找电话号码
  • 检查电话号码是否可单击
  • 如果没有,则使其可单击
  • 有人能帮我解决这个问题吗

    代码:

        URL = driver.get("url.com")
        
        try:
            element = driver.find_element_by_xpath("//*[text()='(123) 111-1234']")
            if element.is_displayed():
                print("Phone number found")
        
                    
        except NoSuchElementException:
            print("Phone number not found")
    
    文本:

        URL = driver.get("url.com")
        
        try:
            element = driver.find_element_by_xpath("//*[text()='(123) 111-1234']")
            if element.is_displayed():
                print("Phone number found")
        
                    
        except NoSuchElementException:
            print("Phone number not found")
    

    Lorem Ipsum只是印刷和排版行业的虚拟文本。自打16世纪(123)111-1234年,一位不知名的印刷商拿着一个铅字槽,将其拼凑成一本铅字样本书后,Lorem Ipsum就一直是业界标准的虚拟文本。它不仅存活了五个世纪,而且还跨越到(123)111-1234电子排版,基本上保持不变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表单的发布而流行,最近随着Aldus PageMaker等桌面出版软件的发布而流行,包括(123)111-1234版本的Lorem Ipsum

    如果可能,您能否提供HTML代码或URL?如何使电话号码可点击?@vitaliis通过在其href中添加电话号码。我稍后会这样做,但现在,我正在努力解决这个问题。我如何搜索电话号码。你能帮我解决这个问题吗?@Sonali我在这个网站上测试>你能帮我解决这个问题吗?