python-3.x 如何在RedBubble中绕过此问题

twh00eeo  于 2023-04-13  发布在  Python
关注(0)|答案(2)|浏览(137)

我刚刚编写了一个RedBubble自动上传程序,但在登录时一切都很完美,但经过一段时间,我尝试了验证码,我无法解决它,我也尝试了cookie = driver.get_cookies() *,并获得了cookie,并使用 * driver.add_cookie(cookie)打印cookie。但我仍然无法登录到网站,也同时做手动,我只是得到了一个弹出在打开dialgoe框我怎么能处理弹出。
我的概念是我需要上传的文件使用CSV这是我的概念。
我已经附上了参考代码可以任何人请帮助我。

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time

path = Service(r'C:\Users\yazha\OneDrive\Pictures\New folder\chromedriver.exe')
driver = webdriver.Chrome(service=path)
driver.get('https://www.redbubble.com/')driver.find_element(By.LINK_TEXT, "Login").click()
time.sleep(10)
driver.find_element(By.ID, "ReduxFormInput1").clear()
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput1").send_keys("")
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput2").clear()

driver.find_element(By.ID, "ReduxFormInput2").send_keys("")
time.sleep(10)
driver.find_element(By.XPATH,"//*[@id='RB_React_Component_LoginFormContainer_0']/div/form/div[3]/div[1]/div/label").is_selected()
driver.find_element(By.CLASS_NAME, "app-ui-components-Button-Button_button_1_MpP").click()

cookies = driver.get_cookies()
print(cookies)
# Create a new instance of the chrome
driver = webdriver.Chrome(service=path)

# Navigate to the website
driver.get('https://www.redbubble.com/')
time.sleep(20)

for cookie in cookies:

driver.add_cookies(cookie)

driver.refresh()
bhmjp9jg

bhmjp9jg1#

首先,您需要使用您的用户名/电子邮件和密码登录,就像您在上面的脚本中所做的那样。
接下来,您应该保存cookie,以便下次继续,您只需加载这些cookie即可直接打开已登录的网站。

json_object = json.dumps(driver.get_cookies())
# save the cookies in a file 
with open("cookies.json", "w") as outfile:
    outfile.write(json_object)

下一次,你只需要直接去网站,加载cookie并刷新它。

# open then website
driver.get("https://www.redbubble.com/")

f = open('cookies.json')
cookies = json.loads(f)
# Load cookies to the driver
for cookie in cookies:
    driver.add_cookie(cookie)

time.sleep(2)

# refresh the browser
driver.refresh()
im9ewurl

im9ewurl2#

谢谢你的解决方案,现在这里的问题是当点击上传URL时检测到cloudflare;我不知道我已经使用了循环的概念来摆脱cloudflare,但它没有检测到cloudflare按钮。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
import time
import json
import os

driver = webdriver.Chrome()
driver.maximize_window()

path = Service(r'C:\Users\yazha\OneDrive\Pictures\New folder\chromedriver.exe')
driver = webdriver.Chrome(service=path)
driver.get('https://www.redbubble.com/')
driver.find_element(By.LINK_TEXT, "Login").click()
time.sleep(10)
driver.find_element(By.ID, "ReduxFormInput1").clear()
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput1").send_keys("motivation14")
time.sleep(4)
driver.find_element(By.ID, "ReduxFormInput2").clear()

driver.find_element(By.ID, "ReduxFormInput2").send_keys("PoojaYazhal1401199921101999@@@")
time.sleep(10)
driver.find_element(By.XPATH,"//*[@id='RB_React_Component_LoginFormContainer_0']/div/form/div[3]/div[1]/div/label").is_selected()
driver.find_element(By.CLASS_NAME, "app-ui-components-Button-Button_button_1_MpP").click()

json_cookies = json.dumps(driver.get_cookies())
with open("cookies.json", "w") as outfile:
    outfile.write(json_cookies)
time.sleep(10)
driver.get("https://www.redbubble.com/portfolio/images/new")
wait = WebDriverWait(driver, 20)
cf_element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "label.ctp-checkbox-label")))
num_attempts = 0
while True:
    try:
        cf_element.click()
        num_attempts += 1
        wait.until(EC.invisibility_of_element(cf_element))
        cf_element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "select-image-single")))
    except Exception as e:
        print(f"Cloudflare captcha bypassed {num_attempts} times.")
        break
        
with open("cookies.json", "r") as infile:
    json_cookies = json.load(infile)
for cookie in json_cookies:
    driver.add_cookie(cookie)
    time.sleep(2)
    
driver.find_element(By.ID, "select-image-single").click()

driver.refresh()

相关问题