Python 选择html文本代码的特定文本部分

Python 选择html文本代码的特定文本部分,python,python-3.x,selenium,web-scraping,beautifulsoup,Python,Python 3.x,Selenium,Web Scraping,Beautifulsoup,请问,如何从这个html中获取文本“没有事件,请稍后再试” ...</option></select><!-- --></div><div class="media_container__no-match-tracker"><div><div><div class="icon icon--football icon--size_auto"></div>

请问,如何从这个html中获取文本“没有事件,请稍后再试”

...</option></select><!-- --></div><div class="media_container__no-match-tracker"><div><div><div class="icon icon--football icon--size_auto"></div><div class="icon icon--volleyball icon--size_auto"></div><div class="icon icon--handball icon--size_auto"></div><div class="icon icon--hockey icon--size_auto"></div><div class="icon icon--basketball icon--size_auto"></div><div class="icon icon--tennis icon--size_auto"></div></div> There is no event, try later. </div></div></div></div></div><div class="app_column__bottom_row" data-v-eb1959b8=""><div class="app_column__bottom_row_wrapper" data-v-eb1959b8=""><div class="app_column__bottom_row_content" data-v-eb1959b8=""><div class="tab_menu chatMenu" data-v-4d018892="" data-v-eb1959b8=""><div ...
但只返回:

<selenium.webdriver.remote.webelement.WebElement (session="d79e3bdd44586c81ae5922410f0c20dd", element="405526fe-7e1a-4552-af5a-70cfb341e129")>


我使用蟒蛇3,硒,bs4,无头铬。谢谢。

阅读代码和html有点困难,但请尝试以下xpath定位器:

//div[@class='media_container__no-match-tracker']
并返回元素的文本:

driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text
@德马特

谢谢,这是我需要的。我能再问一个问题吗?站点是动态的,所以这个元素并不是每一个代码中我都能找到的。如果没有,这个驱动程序。找到。。。返回:

        driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
driver.find_element_by_xpath('//div[@class=“media\u container\uu no-match-tracker”]')。text
文件“C:\Users\Miro\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第394行,位于按xpath查找元素中
返回self.find_元素(by=by.XPATH,value=XPATH)
文件“C:\Users\Miro\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第978行,在find\u元素中
'value':value})['value']
文件“C:\Users\Miro\Anaconda3\lib\site packages\selenium\webdriver\remote\webdriver.py”,第321行,在execute中
self.error\u handler.check\u响应(响应)
文件“C:\Users\Miro\Anaconda3\lib\site packages\selenium\webdriver\remote\errorhandler.py”,第242行,在check\u响应中
引发异常类(消息、屏幕、堆栈跟踪)
NoSuchElementException:没有这样的元素:无法找到元素:{“方法”:“xpath”,“选择器”:”//div[@class=“media\u container\uuu no-match-tracker”]}
(会话信息:无头镀铬=86.0.4240.193)

我怎样才能把它作为条件呢?如果元素在站点上,请打印它,如果不打印(“元素不在此url上”)。

请共享您尝试的完整代码/链接到website@MendelG链接:我需要找到文本:“Tento zápas nemátracker,vyberte si iný。”你需要找到。找到元素后发送文本。等待:@DMart谢谢
        driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text
Traceback (most recent call last):



  File "<ipython-input-95-8dcfa123bd2a>", line 1, in <module>
    driver.find_element_by_xpath('//div[@class="media_container__no-match-tracker"]').text

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
    'value': value})['value']

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)

  File "C:\Users\Miro\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)

NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class="media_container__no-match-tracker"]"}
  (Session info: headless chrome=86.0.4240.193)