Python 中的多处理不适用于 Selenium
我很诚实,所以我使用 Selenium 的原因是因为我尝试制作 Instagram 垃圾邮件机器人,它会向很多人发送消息,我会要求他们不要对俄罗斯入侵乌克兰保持沉默,因为我'我是乌克兰人,周围发生的事情是如此可怕和可怕。我有责任尽我所能帮助阻止它!
说明: 这是 multishare() 函数,它是从另一个创建 self.followers 集的函数调用的,该集包含将被发送文本的人员的用户名。在 multishare() 函数中,我将 self.followers 重新定义为一个列表,并将其分成 4 个相等的部分,以使垃圾邮件发送者的速度提高四倍。然后我通过多处理调用 share() 函数,但它甚至没有打开 Chrome。 下面你可以看到代码。 这是代码:
def multishare(self):
self.followers = list(self.followers)
ftq = int(len(self.followers) // 4)
sq = int(len(self.followers) // 2)
tq = int(len(self.followers) // 1.33)
fhq = len(self.followers)
first_part = self.followers[0:ftq]
second_part = self.followers[ftq:sq]
third_part = self.followers[sq:tq]
fourth_part = self.followers[tq:fhq]
self.followers = [first_part, second_part, third_part, fourth_part]
pool = Pool(processes=4)
pool.map(self.share, self.followers)
def share(self, users):
self.safe_get('https://www.instagram.com/')
for user in users:
time.sleep(1)
self.safe_get('https://www.instagram.com/direct/inbox/')
self.element_existence('//*[@id="react-root"]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button').click()
time.sleep(1)
search_user = self.element_existence('/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input')
search_user.clear()
time.sleep(1)
search_user.send_keys(user)
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[2]/div[1]/div/div[3]/button").click()
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input").click()
这就是我得到的错误:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/timeouts (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa5089d4250>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
所以我实际上无法解决这个问题。 **这与多重处理无关,我的主要目标是使垃圾邮件发送者尽可能快。因此,如果您有更好的想法或只是知道如何解决我的问题,请帮助我!
I am being honest, so the reason I use Selenium is because I try to make instagram spam-bot which will send messages to many people where I will ask them to not to be quiet about Russian invasion in Ukraine, because I'm Ukrainian and it's so awful and terrifying what happens around. And this is my duty to help to stop it as mush as I can!
Explanation:
Here is the multishare() function which is called from another function that creates self.followers set, that contains usernames of people who will be sent text. In multishare() function I redefine self.followers as a list and separate it into 4 equal parts to make spammer four times faster. And then I call share() function through the multiprocessing, but it doesn't even open Chrome.
Below you see the code.
Here is the code:
def multishare(self):
self.followers = list(self.followers)
ftq = int(len(self.followers) // 4)
sq = int(len(self.followers) // 2)
tq = int(len(self.followers) // 1.33)
fhq = len(self.followers)
first_part = self.followers[0:ftq]
second_part = self.followers[ftq:sq]
third_part = self.followers[sq:tq]
fourth_part = self.followers[tq:fhq]
self.followers = [first_part, second_part, third_part, fourth_part]
pool = Pool(processes=4)
pool.map(self.share, self.followers)
def share(self, users):
self.safe_get('https://www.instagram.com/')
for user in users:
time.sleep(1)
self.safe_get('https://www.instagram.com/direct/inbox/')
self.element_existence('//*[@id="react-root"]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button').click()
time.sleep(1)
search_user = self.element_existence('/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input')
search_user.clear()
time.sleep(1)
search_user.send_keys(user)
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[2]/div[1]/div/div[3]/button").click()
time.sleep(1)
self.element_existence("/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input").click()
And that's the errors that I got:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/timeouts (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa5089d4250>: Failed to establish a new connection: [Errno 111] Connection refused'))
During handling of the above exception, another exception occurred:
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=37193): Max retries exceeded with url: /session/5f6dd5e3e048e0bd62e2dd4b1aa5e8ae/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fa50c23d1f0>: Failed to establish a new connection: [Errno 111] Connection refused'))
So I cant actually solve this. **It's not about multiprocessing, my main target is to make spammer as fast as it possible. So if u have better idea or just know how to solve my issue, help me please !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论