简体   繁体   中英

Bypass Access Denied (selenium)

I'm trying to navigate a website with Selenium I searched Google and said that adding user-agent would solve it, but it didn't solve it. http://coupang.com/

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time

options = Options()

options = webdriver.ChromeOptions()
# options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument('lang=ko_KR')
options.add_argument("--disable-gpu")
options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5")
options.add_argument("accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
options.add_argument("accept-charset=cp1254,ISO-8859-9,utf-8;q=0.7,*;q=0.3")
options.add_argument("accept-encoding=gzip,deflate,sdch")
options.add_argument("accept-language=tr,tr-TR,en-US,en;q=0.8")
driver = webdriver.Chrome('d:/temp/chromedriver.exe',options=options)

TEST_URL = 'https://login.coupang.com/login/login.pang?rtnUrl=https%3A%2F%2Fwww.coupang.com%2Fnp%2Fpost%2Flogin%3Fr%3Dhttps%253A%252F%252Fwww.coupang.com%252F'


driver.get(TEST_URL)
time.sleep(5)
driver.implicitly_wait(3)

elem_login = driver.find_element_by_id("login-email-input")
elem_login.clear()
elem_login.send_keys("id")
time.sleep(3)
elem_login = driver.find_element_by_id("login-password-input")
elem_login.clear()
elem_login.send_keys("pw")
time.sleep(3)
xpath = "/html/body/div[1]/div/div/form/div[5]/button"
driver.find_element_by_xpath(xpath).click()
driver.implicitly_wait(3)

print(driver.page_source)

Can you try and add headers like so and tell me if it works.

headers = {
    "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5)",
    "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
    "accept-charset": "cp1254,ISO-8859-9,utf-8;q=0.7,*;q=0.3",
    "accept-encoding": "gzip,deflate,sdch",
    "accept-language": "tr,tr-TR,en-US,en;q=0.8",

Not that crystal clear in which circumstances you are facing Access Denied . However I was able to access the webpage http://coupang.com/ as follows:

options = webdriver.ChromeOptions() 
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('lang=ko_KR')
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www.coupang.com/')
print(driver.page_source)

Console Output:

<!--[if lte IE 9]>
<div id="browserSupportWrap">
    <div class="bs-wrap">
    <p class="bs-message">고객님의 브라우저에서는 쿠팡이 정상 동작하지 않습니다.<br />
        인터넷 익스플로러 업데이트, 크롬 또는 파이어폭스 브라우저를 설치하세요.</p>
    <ul class="bs-browser-download">
        <li class="ie"><a href="http://windows.microsoft.com/ko-kr/internet-explorer/download-ie" target="_blank">인터넷 익스플로러<br /> <em>업데이트하기</em></a></li>
        <li class="chrome"><a href="https://www.google.com/chrome/browser/desktop/index.html" target="_blank">크롬<br /> <em>설치하기</em></a></li>
        <li class="firefox"><a href="https://www.mozilla.org/ko/firefox/new/" target="_blank">파이어폭스<br /> <em> 설치하기</em></a></li>
    </ul>
    </div>
</div>
<![endif]-->




    <div id="container" class="renewal home srp-sync srp-sync-brand">
.
</script>


    <!-- Facebook Pixel Code -->
<script>
    !function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
    n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
    t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
        document,'script','https://connect.facebook.net/en_US/fbevents.js');
    fbq('init', '652323801535981');
    fbq('track', 'PageView');

</script>
<noscript><img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=652323801535981&ev=PageView&noscript=1"/></noscript>
<!-- End Facebook Pixel Code -->


    <script type="text/javascript" src="//asset2.coupangcdn.com/customjs/criteo/5.6.1/ld.min.js" async="true"></script>




<noscript><img src="https://www.coupang.com/akam/11/pixel_3401c526?a=dD1kMDI3YTFiY2NmYTZiMDg3ZDE3ZWRkNzc3MDI5ZDhhNzNiYzM4ZDkxJmpzPW9mZg==" style="visibility: hidden; position: absolute; left: -999px; top: -999px;" /></noscript>




<iframe height="0" width="0" title="Criteo DIS iframe" style="display: none;"></iframe></body></html>

Browser Snapshot:

库邦

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM