그래서 나는 Firefox를 통해 프록시로 Tor 브라우저를 통해 특정 사이트 (dumpert.nl)에 액세스하려고했습니다. 제가 Tor 브라우저를 사용하는 이유는 웹 사이트에 들어갈 때마다 다른 IP 주소로 웹 사이트에 들어갈 수 있기 때문입니다. 나는 이것이 가능하다는 것을 알고 있지만 아직 이것을 할 방법을 찾지 못했습니다. 이 작업을 수행하는 여러 가지 방법을 찾았지만 (아직) 나를 위해 일하지 않았습니다. 이 부분에 대해서도 도움이 필요합니다.
진짜 문제는이 웹 사이트의 쿠키 허용 페이지에 문제가 있다는 것입니다. 쿠키를 수락하기 위해 수동으로 버튼을 클릭해도 아무 일도 일어나지 않습니다. 다음 페이지로 진행할 수 없습니다. 셀레늄의 .click () 함수를 사용하면 아무 일도 일어나지 않으며 페이지가 완전히로드되면 문제가되지 않습니다. 버튼이 어떤 이유로 작동하지 않으며 이유가 없습니다. Tor 문제인지 아니면 Tor 문제를 통해 firefox를 사용하는지 모르겠습니다.
다음 코드를 사용하여 웹 사이트로 이동합니다.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
torexe = os.popen(r'C:\Users\nick\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\nick\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\Webdrivers\geckodriver.exe')
driver.get("http://dumpert.nl")
driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/a").click() #cookie click
#Rest of my code doing stuff not important for this issue
웹 페이지를 열려면 http://dumpert.nl
및 click()
원하는 버튼에 당신은 유도해야 WebDriverWait을 을 위해 element_to_be_clickable()
당신은 다음 중 하나를 사용할 수 있습니다 로케이터 전략 :
사용 CSS_SELECTOR
:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
torexe = os.popen(r'C:\Users\Soma Bhattacharjee\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\Soma Bhattacharjee\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get("http://dumpert.nl")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.approve-btn[title^='And yes']>span"))).click()
사용 XPATH
:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
torexe = os.popen(r'C:\Users\Soma Bhattacharjee\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\Soma Bhattacharjee\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default')
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile= profile, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get("http://dumpert.nl")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='approve-btn']/span[starts-with(., 'Yes')]"))).click()
브라우저 스냅 샷 :
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다