-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresult.py
More file actions
158 lines (130 loc) · 6.29 KB
/
Copy pathresult.py
File metadata and controls
158 lines (130 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import csv
import threading
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
def read_phone_numbers(file_path):
phone_numbers = []
with open(file_path, mode='r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
for cell in row:
if cell.strip().isdigit():
phone_numbers.append(cell.strip())
return phone_numbers
def read_proxies(file_path):
proxies = []
with open(file_path, mode='r') as file:
csv_reader = csv.reader(file)
for row in csv_reader:
if row: # Ensure the line is not empty
proxies.append(row[0].strip()) # Add the whole line as a proxy string
return proxies
def setup_driver(proxy):
service = ChromeService(ChromeDriverManager().install())
options = webdriver.ChromeOptions()
# Proxy configuration
if proxy:
proxy_parts = proxy.split(':')
if len(proxy_parts) == 4: # Expected format: url:port:user:password
proxy_host, proxy_port, proxy_user, proxy_password = proxy_parts
proxy_str = '{hostname}:{port}'.format(hostname=proxy_host, port=proxy_port)
options.add_argument('--proxy-server={}'.format(proxy_str))
else:
print("Invalid proxy format, skipping proxy setup.")
options.add_argument("--window-size=460,820")
options.add_argument("--window-position=0,0")
driver = webdriver.Chrome(service=service, options=options)
return driver
def automate_login(phone_numbers, proxy):
driver = setup_driver(proxy)
try:
driver.get("https://m.uber.com/")
cont = input("Can we continue: ").strip()
cnt = 350
cnt_otp = 0
while(1):
phone = phone_numbers[cnt]
cnt = cnt + 1
cnt_otp = cnt_otp + 1
if cnt_otp == 250:
time.sleep(1800)
cnt_otp = 0
try:
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.TAG_NAME, "span")))
spans = driver.find_elements(By.TAG_NAME, "span")
for span in spans:
span.click()
break
actions = webdriver.ActionChains(driver)
actions.send_keys('a').send_keys('z').send_keys(Keys.RETURN).perform()
phone_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "input"))
)
input_tags = driver.find_elements(By.XPATH, "//input[@aria-label='Please enter a phone number without the country dial code.']")
for input_tag in input_tags:
input_tag.send_keys(phone)
break
continue_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.TAG_NAME, "button"))
)
button_tags = driver.find_elements(By.TAG_NAME, "button")
for button_tag in button_tags:
print(button_tag.text)
if (button_tag.text == 'Update'):
button_tag.click()
break
print(f"Phone number {phone} entered and 'Update' clicked")
time.sleep(2)
invalid_buttons = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.TAG_NAME, "button"))
)
invalid_buttons = driver.find_elements(By.TAG_NAME, "button")
invalid_flag = 0
for invalid_tag in invalid_buttons:
print(invalid_tag.text)
if invalid_tag.text == 'Update':
invalid_flag = 1
break
if invalid_flag == 1:
print("invaild case")
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "input"))
)
ainput_tags = driver.find_elements(By.XPATH, "//input[@aria-label='Please enter a phone number without the country dial code.']")
for ainput_tag in ainput_tags:
ainput_tag.click() # Ensure the input field is focused
ainput_tag.send_keys(Keys.CONTROL + "a") # Select all text (use Command for Mac: Keys.COMMAND)
ainput_tag.send_keys(Keys.BACKSPACE) # Delete the selected text
print("Value cleared using backspace")
else :
button = driver.find_element(By.XPATH, "//button[@data-testid='enter-otp-ui.navigation.back-button']")
button.click()
time.sleep(1)
except Exception as e:
print(f"Error during automation for phone {phone}: {e}")
finally:
cont = input("Can we continue: ").strip()
time.sleep(10)
driver.quit()
def main():
phone_csv_path = 'phone2.csv'
proxy_csv_path = 'proxy.csv'
# Read data from CSV files
phone_numbers = read_phone_numbers(phone_csv_path)
proxies = read_proxies(proxy_csv_path)
# Input the head number to remove from all phone numbers
head_number = input("Enter the head number to remove from each phone number (if present): ").strip()
phone_numbers = [phone[len(head_number):] if phone.startswith(head_number) else phone for phone in phone_numbers]
# Determine the minimum length between phone numbers and proxies
repeat_count = min(len(phone_numbers), len(proxies))
print(f"Repeating the automation {repeat_count} times")
proxy = proxies[0]
automate_login(phone_numbers, proxy)
if __name__ == "__main__":
main()