-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUber.py
More file actions
147 lines (122 loc) · 5.45 KB
/
Copy pathUber.py
File metadata and controls
147 lines (122 loc) · 5.45 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
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
# Function to read phone numbers from phone.csv
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
# Function to read proxies from proxy.csv
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
# Function to set up a Chrome WebDriver instance with proxy settings
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
# Function to automate Uber login
def automate_login(phone, proxy):
driver = setup_driver(proxy)
try:
driver.get("https://m.uber.com/")
# try:
# cookie_button = WebDriverWait(driver, 10).until(
# EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), 'Accept')]"))
# )
# cookie_button.click()
# print("Cookie consent accepted.")
# except Exception as e:
# print("No cookie consent button found or unable to interact with it:", e)
# # Locate and interact with the "Sign up" button
try:
cont = input("Can we continue: ").strip()
WebDriverWait(driver, 10).until(EC.presence_of_all_elements_located((By.TAG_NAME, "span")))
buttons = driver.find_elements(By.TAG_NAME, "span")
for button in buttons:
print(button)
button.click()
break
actions = webdriver.ActionChains(driver)
actions.send_keys('a').send_keys('z').send_keys(Keys.RETURN).perform()
# # Wait and click "Sign up for Uber for Business" link
# signup_for_business_link = WebDriverWait(driver, 10).until(
# EC.element_to_be_clickable((By.LINK_TEXT, "Sign up for Uber for Business"))
# )
# signup_for_business_link.click()
# Input the phone number and click "Continue"
phone_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.TAG_NAME, "input"))
)
continue_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, "forward-button"))
)
continue_button.click()
print(f"Phone number {phone} entered and 'Continue' clicked")
except Exception as e:
print(f"Error during automation for phone {phone}: {e}")
finally:
time.sleep(10)
driver.quit()
def main():
phone_csv_path = 'phone.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")
# Number of browsers to open concurrently
max_concurrent_browsers = int(input("Enter the maximum number of browsers to open at once: "))
# Launch sessions in batches
threads = []
for i in range(len(phone_numbers)):
phone = phone_numbers[i]
proxy = proxies[i]
# Create and start a new thread for each automation task
thread = threading.Thread(target=automate_login, args=(phone, proxy))
threads.append(thread)
thread.start()
# Manage the number of open threads
if len(threads) >= max_concurrent_browsers:
for thread in threads:
thread.join()
threads = []
# Wait for any remaining threads to finish
for thread in threads:
thread.join()
if __name__ == "__main__":
main()