python - 错误:来自 csv 的 Python Whatsapp 消息。汽车
问题描述
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
import csv
import time
caps = DesiredCapabilities().CHROME
options = webdriver.ChromeOptions()
prefs = {'profile.default_content_setting_values': {'images': 2}}
options.add_experimental_option('prefs', prefs)
options.add_argument("start-maximized")
driver = webdriver.Chrome(desired_capabilities = caps,options = options)
file_name = 'Projeto3.csv'
csvfile = open(file_name,'rt')
csvReader = csv.reader(csvfile, delimiter = ",")
list_ = list()
for row in csvReader:
list_.append((row[0],row[1]))
length = len(list_)
counter = 0
class send_message_to:
def __init__ (self, name, phonenumber):
self.name = name
self.phonenumber = phonenumber
def start():
driver.get('https://web.whatsapp.com/')
while True:
try:
driver.find_element_by_xpath('//*[@id="side"]/div[1]/div/div')
break
except:
print("Please scan QR code")
time.sleep(2)
reciver = send_message_to(list_[counter][0],list_[counter][1])
message = 'Hi {}, this is a important message'.format(reciver.name)
url = 'https:api.whatsapp.com/send?phone={}'.format(reciver.phonenumber)
driver.get(url)
while True:
try:
driver.find_element_by_xpath('//*[@id="action-button"]').click()
break
except:
pass
while True:
try:
element = driver.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
element.click()
element.send_keys(message)
element.send_keys(Keys.ENTER)
break
except:
pass
for i in range(0,length):
start(counter)
counter = +1
错误:
Traceback (most recent call last):
File "C:\Program Files (x86)\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Program Files (x86)\Python38-32\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files (x86)\Python38-32\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] O sistema não pode encontrar o arquivo especificado
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\victo\Desktop\Victor\Python Learning\Project 03 - Whatsapp\Projeto3.py", line 15, in <module>
driver = webdriver.Chrome(desired_capabilities = caps,options = options)
File "C:\Program Files (x86)\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Program Files (x86)\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException:消息:“chromedriver”可执行文件需要在 PATH 中。请参阅https://sites.google.com/a/chromium.org/chromedriver/home
解决方案
尝试将此添加到您的代码中:
chromedriver = "/path/to/chromedriver"
options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(chromedriver, chrome_options=options)
推荐阅读
- azure-active-directory - Azure AD 企业应用程序 - 识别调用者应用程序
- r - 从源代码编译 R 包的多个不同错误
- c# - 通过 ajax 将 XML 属性与 Elements 一起发送到 C# 控制器方法并解析以保存
- python - 如何使用 time.sleep() 绘制圆圈 Tkinter?
- javascript - 更改 JavaScript 函数以删除 HTML 标记,除了
- postgresql - 如果为空,则返回替代值?
- javascript - 如何将 javascript 插件添加到 vaadin 网站
- r - 在 R Studio 上使用 API 进行人口普查数据
- python - 'QuerySet' 对象没有属性 '_meta' 模型查询到 JSON 格式
- java - 如何通过使用-MapStruct从源对象复制值来填充目标对象内的地图?