У меня парсер на Python и Selenium работает, а у знакомого нет, в чём проблема?

Добрый день! Помогите решить проблему. Попросили написать скрипт, который парсит номера из WhatsApp Web. Я написал скрипт, с помощью PyInstaller создал exe шник. На моём компьютере и на моём старом, где даже pythonа нет работает всё корректно и как надо. Но вот у знакомого почему-то вылетает скрипт. Chrome Driver стоит на всех 3-х компах.

Принцип работы такой:
Открывается хром с вкладкой WhatsAppWeb. Программа ждёт пока пользователь авторизуется и нажмёт Enter в открывшейся консоли, затем начинает парсить.

У знакомого открывается окно, он авторизуется, нажимает Enter и всё закрывается. Живёт в другом городе, поэтому сам разобраться не с могу, может подскажете в чём может быть проблема?!(

Вот код:
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException, ElementClickInterceptedException, WebDriverException, ElementNotInteractableException
from time import sleep, time

timeout = 10


def click_option_btn():
	attr = ""
	x = 1
	while attr != "Menu":
		opt_btn = browser.find_element_by_xpath("//*[@id='main']/header/div[3]/div/div[%i]/div" % x)
		attr = opt_btn.get_attribute("title")
		x += 1
	opt_btn.click()


def click_userinfo_btn():
	start_time = int(time())
	while time() < start_time + timeout:
		try:
			user_info_btn = browser.find_element_by_xpath("//*[@id='main']/header/div[3]/div/div[3]/span/div/ul/li[1]")
		except NoSuchElementException:
			user_info_btn = browser.find_element_by_xpath("//*[@id='main']/header/div[3]/div/div[2]/span/div/ul/li[1]")
		try:
			user_info_btn.click()
			break
		except ElementNotInteractableException:
			print("Cannot click(")
			sleep(0.2)
		except ElementClickInterceptedException:
			print("Cannot click(")
			sleep(0.2)


def click_chat_btn():
	btns = browser.find_elements_by_class_name("_3j8Pd")
	for element in btns:
		obj = element.find_element_by_tag_name("div")
		if obj.get_attribute("title") == "New chat":
			obj.click()
			break


try:
	browser = webdriver.Chrome()

except WebDriverException:
	print("Problem with ChromeDriver")
	input("Enter some to quit.")

else:
	browser.get("https://web.whatsapp.com/")

	phone_number = "+7000000000"
	numbers = []

	# Waiting authorization
	input("Please authorize in WhatsAppWeb, wait a few second and press Enter.")
	i = 2
	# Parse numbers
	while True:
		click_chat_btn()

		try:
			person = browser.find_element_by_xpath("//*[@id='app']/div/div/div[2]/div[1]/span/div/span/div/div[2]/div[2]/div/div/div[%i]" % i)
		except NoSuchElementException:
			break

		start_time = int(time())
		while time() < start_time + timeout:
			try:
				person.click()
				break
			except ElementClickInterceptedException:
				print("Failed to click!")
				sleep(0.1)
			except ElementNotInteractableException:
				print("Failed to click!")
				sleep(0.1)

		click_option_btn()

		click_userinfo_btn()

		phone_number = ""

		start_time = int(time())
		while time() < start_time + timeout:
			try:
				# Waiting while field is empty
				while len(phone_number) <= 1:
					# Write user number phone
					phone_number = browser.find_element_by_xpath("//*[@id='app']/div/div/div[2]/div[3]/span/div/span/div/div/div[1]/div[4]/div[3]/div/div/span/span").text
				break
			except NoSuchElementException:
				print("Cannot find element")
				sleep(0.3)

		numbers.append(phone_number)
		i += 1

	print(numbers)

	# Clear useless symbols
	useless_symbols = "()+ .-"
	correct_numbers = []
	for ph_number in numbers:
		for sym in useless_symbols:
			ph_number = ph_number.replace(sym, "")
		correct_numbers.append(ph_number)

	numbers = correct_numbers
	correct_numbers = []

	# Delete same phone numbers
	for i in numbers:
		if i not in correct_numbers:
			correct_numbers.append(i)

	# Writing numbers in file
	numbers_file = open("Numbers.txt", "w")

	for num in correct_numbers:
		numbers_file.write("%s\n" % num)

	# Closing File
	numbers_file.close()
	browser.quit()
  • Вопрос задан
  • 678 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы