title: Login to Zhihu with Python selenium
body: <p>I want to login to <a href="https://zhihu.com" rel="nofollow noreferrer">Zhihu</a>, a Chinese Q&amp;A site. The login URL is <a href="https://www.zhihu.com/signin?next=%2F" rel="nofollow noreferrer">https://www.zhihu.com/signin?next=%2F</a>. Click on the second tab with text <code>密码登录</code> to view the login form. I wanted to login to it, but when I submit the form with all information correctly, it fails. There is a <code>sign_in</code> request with status <code>403</code> when I submit the form. I've tried to set the <code>window.navigator.webdriver</code> option to <code>true</code>, setting <code>add_experimental_option(&quot;excludeSwitches&quot;, [&quot;enable-automation&quot;])</code>, or even using pyppeteer, but none of them work. Any ideas for this? Thanks in advance!</p>
  <p>UPDATE:</p>
  <p>My code is below:</p>
  <pre class="lang-py prettyprint-override"><code>from selenium.webdriver import Chrome, ChromeOptions
  
  options = ChromeOptions()
  # options.add_argument('--headless')
  options.add_experimental_option(&quot;excludeSwitches&quot;, [&quot;enable-automation&quot;])
  options.add_experimental_option('useAutomationExtension', False)
  driver = Chrome(options=options)
  # Enable the script below to get rid of the `webdriver` property in JavaScript
  driver.execute_cdp_cmd(&quot;Page.addScriptToEvaluateOnNewDocument&quot;, {
      &quot;source&quot;: &quot;&quot;&quot;
          Object.defineProperty(navigator, 'webdriver', {
          get: () =&gt; null
          })
      &quot;&quot;&quot;
  })
  
  
  def login(username, password):
      # Error that may be raised while executing
      error = None
      try:
          driver.get('https://www.zhihu.com/signin?next=%2F')
          psw = driver.find_elements_by_class_name('SignFlow-tab')[1]
          psw.click()
          username_input = driver.find_element_by_name('username')
          username_input.send_keys(username)
          password_input = driver.find_element_by_name('password')
          password_input.send_keys(password)
          btn = driver.find_element_by_class_name('SignFlow-submitButton')
          btn.click()
          print('Please check the captcha.')
      except Exception as err:
          error = err
      finally:
          # Raise the error if detected
          if error:
              print(str(error))
  
  
  login(input('Username: '), input('Password: '))
  
  </code></pre>
  <p>PS: I'm using ChromeDriver version 84.</p>