问了一下:
import platform
import os
def play_sound():
system = platform.system()
if system == “Windows”:
# You can use winsound module for Windows system sounds
import winsound
winsound.Beep(440, 500) # Example: Beep at 440 Hz for 500 milliseconds
elif system == “Darwin”: # macOS
os.system(‘afplay /System/Library/Sounds/Submarine.aiff’)
elif system == “Linux”:
# You need to specify a sound file or command suitable for your Linux distribution
# For example, you could use aplay to play a WAV file
os.system(‘aplay /usr/share/sounds/alsa/Front_Center.wav’)
else:
print(“Unsupported operating system. Unable to play sound.”)
Test the function
play_sound()
用户特征(特别是ip)不变 怎么刷都是一样的offer 
Sorry
我是assume用这个跑的人至少能读懂代码会debug,能知道把这行删了。
我回头改改,是个很好的建议。我应该关注用户体验。。
1 个赞
现在靠chatGPT, 像我这样半瓶醋的大批群众都冒充程序员 
确实是vs code好用,我也日常用vs code。只是pycharm可能想跑这个程序更傻瓜一些,装上点运行就行
1 个赞
Super helpful - augamented version with user-agent spoofing and cookie management with hard refreshing every 15-25 seconds. Tested with python3.10 on Macbook
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
import time
import os
import random
user_agents = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Mozilla/5.0 (IPhone; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/91.0.4472.124 Mobile/15E148 Safari/604.1",
"Mozilla/5.0 (Android 10; Mobile) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Mobile Safari/537.36",
]
def play_sound():
# Play the default system sound on macOS
os.system('afplay /System/Library/Sounds/Submarine.aiff')
def check_string_in_webpage(url, string_to_check):
chrome_options = Options()
chrome_options.add_argument("--incognito")
chrome_options.add_argument(f"--user-agent={random.choice(user_agents)}")
driver = webdriver.Chrome(options=chrome_options)
# Open the webpage
driver.get(url)
ct = 1
while True:
time.sleep(3)
try:
# close the popup asking for 4 million
svg_element = driver.find_element(By.XPATH, "//svg[@data-src='https://icm.aexp-static.com/Internet/Acquisition/US_en/AppContent/OneSite/Data/SVG/dls/dls-icon-close.svg']")
svg_element.click()
except NoSuchElementException:
pass
try:
if string_to_check in driver.page_source:
try:
print(f"String '{string_to_check}' found in the webpage. ct: {ct}")
play_sound()
button = driver.find_element(By.XPATH, "//button[@title='Click here to apply for Business Platinum Card from American Express']")
button.click()
break
except NoSuchElementException:
print("Success path: Button not found on the page. Will try again...")
else:
print(f"String '{string_to_check}' not found. Attempting to click 'Refresh' button... ct: {ct}")
try:
# Perform a hard refresh
driver.delete_all_cookies()
driver.execute_script("location.reload(true);")
ct += 1
print(f"Fail path: Performed a hard refresh. ct: {ct}")
# Wait for the page to load
time.sleep(5)
try:
# Locate the close button using aria-label
close_button = driver.find_element(By.CSS_SELECTOR, 'button[aria-label="Close"]')
close_button.click()
print("Successfully closed the button.")
except NoSuchElementException:
print("Close button not found after refresh.")
except Exception as e:
print(f"Fail path: Error occurred while refreshing the page: {e}. Will try again...")
# Wait for a random duration between 15 and 25 seconds
sleep_duration = random.randint(15, 25)
time.sleep(sleep_duration)
except NoSuchElementException:
print("Error occurred. Trying again...")
time.sleep(5)
input(f"Press any key to exit... ct: {ct}")
# Close the browser
driver.quit()
url = "https://www.americanexpress.com/en-us/referral/business-platinum-charge-card"
string_to_check = "250,000 Membership"
check_string_in_webpage(url, string_to_check)
1 个赞
卧槽 刚用Virginia IP开着脚本没过多久就刷到了250k