我已经尝试了大约2周,但没有成功-如何使用硒获取在WhatsApp上拥有的所有聊天名称? 我尝试了所有方法,但在互联网上找不到任何类似的问题, 帮助将不胜感激
这是应该执行的代码部分,但仅适用于前20-30,然后停止:
driver = webdriver.Firefox(executable_path=r'PATH')
driver.get('https://web.whatsapp.com/')
input("scan qr")
driver.get('https://web.whatsapp.com/send?phone=PHONE_NUMBER&text=&source=&data=')
time.sleep(13)
driver.find_element_by_xpath('//*[@id="main"]/header/div[2]/div/div/span').click()
time.sleep(2)
driver.find_element_by_xpath(
'//*[@id="app"]/div/div/div[2]/div[3]/span/div/span/div/div/div/div[5]/div[3]/div[2]/div/div').click()
time.sleep(2)
counter = 1
while True:
group = driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/div[3]/span/div/span/div/ \
div/div/div[5]/div[2]/div/div[' + str(counter) + ']/ \
div/div/div[2]/div[1]/div/span')
name = group.get_attribute('title')
print(name)
counter += 1
我得到的错误:
Traceback (most recent call last):
File "C:/Users/Roy/PycharmProjects/WhatsApp Bot/test.py", line 34, in <module>
div/div/div[2]/div[1]/div/span')
File "C:\Users\Roy\AppData\Roaming\Python\Python36\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\Roy\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Roy\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Roy\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[@id="app"]/div/div/div[2]/div[3]/span/div/span/div/ div/div/div[5]/div[2]/div/div[23]/