<tfoot id='TitW7'></tfoot>
  • <legend id='TitW7'><style id='TitW7'><dir id='TitW7'><q id='TitW7'></q></dir></style></legend>
    <i id='TitW7'><tr id='TitW7'><dt id='TitW7'><q id='TitW7'><span id='TitW7'><b id='TitW7'><form id='TitW7'><ins id='TitW7'></ins><ul id='TitW7'></ul><sub id='TitW7'></sub></form><legend id='TitW7'></legend><bdo id='TitW7'><pre id='TitW7'><center id='TitW7'></center></pre></bdo></b><th id='TitW7'></th></span></q></dt></tr></i><div id='TitW7'><tfoot id='TitW7'></tfoot><dl id='TitW7'><fieldset id='TitW7'></fieldset></dl></div>

          <bdo id='TitW7'></bdo><ul id='TitW7'></ul>

      1. <small id='TitW7'></small><noframes id='TitW7'>

      2. Selenium/Python - 提交表单后提取动态生成的 HTML

        Selenium/Python - Extract dynamically generated HTML after submitting form(Selenium/Python - 提交表单后提取动态生成的 HTML)
          • <bdo id='GGfnT'></bdo><ul id='GGfnT'></ul>
            <i id='GGfnT'><tr id='GGfnT'><dt id='GGfnT'><q id='GGfnT'><span id='GGfnT'><b id='GGfnT'><form id='GGfnT'><ins id='GGfnT'></ins><ul id='GGfnT'></ul><sub id='GGfnT'></sub></form><legend id='GGfnT'></legend><bdo id='GGfnT'><pre id='GGfnT'><center id='GGfnT'></center></pre></bdo></b><th id='GGfnT'></th></span></q></dt></tr></i><div id='GGfnT'><tfoot id='GGfnT'></tfoot><dl id='GGfnT'><fieldset id='GGfnT'></fieldset></dl></div>

            <legend id='GGfnT'><style id='GGfnT'><dir id='GGfnT'><q id='GGfnT'></q></dir></style></legend>

                • <tfoot id='GGfnT'></tfoot>

                  <small id='GGfnT'></small><noframes id='GGfnT'>

                    <tbody id='GGfnT'></tbody>
                  本文介绍了Selenium/Python - 提交表单后提取动态生成的 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我尝试访问的网页是使用 JavaScript 动态生成 HTML 表单(这个:https://imgur.com/a/rhmXB).输入 print(page_source) 时,表格似乎出现在输出的 HTML 中.

                  The web page I am trying to access is using JavaScript to dynamically generate HTML form(this one: https://imgur.com/a/rhmXB ). When typing print(page_source), the table seems to appear in the HTML being outputted.

                  然而,在填写输入字段并提交表单后,会出现另一个带有验证码图像的输入字段(如下所示:https://imgur.com/a/xVfBS ).输入 print(page_source) 后,带有 CAPTCHA 的输入表单似乎没有插入到 HTML 中.

                  However, after filling the input field and submitting the form, another input field with CAPTCHA image appears(as shown here: https://imgur.com/a/xVfBS ). After typing print(page_source), the input form with the CAPTCHA seems not to be inserted into the HTML.

                  我的问题是:如何使用 Selenium 访问这个动态生成的 HTML,其中包含输入字段和验证码图像?

                  My question is: How can I access this dynamically generated HTML, which contains the input field and the CAPTCHA image using Selenium?

                  这是我的代码(另外,in pastebin):

                  Here is my code (also, in pastebin):

                  from selenium import webdriver
                  driver = webdriver.Chrome("/var/chromedriver/chromedriver")
                  
                  URL = 'http://nap.bg/link?id=104'
                  driver.get(URL)
                  
                  input_field = driver.find_element_by_name('ipID')
                  input_field.send_keys('0000000000')
                  driver.find_element_by_id('idSubmit').click()
                  print(driver.page_source)
                  

                  推荐答案

                  点击按钮后,页面需要一些时间来加载验证码等内容.您需要等待它完成加载.您可以使用 Selenium 的 显式等待来做到这一点.

                  After you click on the button, the page takes some time to load the CAPTCHA and other content. You'll need to wait for that to finish loading. You can do that using Selenium's explicit waits.

                  这是你可以做的一个例子:

                  This is an example for what you can do:

                  from selenium import webdriver
                  from selenium.webdriver.support.ui import WebDriverWait
                  from selenium.webdriver.support import expected_conditions as EC
                  from selenium.webdriver.common.by import By
                  
                  driver = webdriver.Chrome()
                  URL = 'http://nap.bg/link?id=104'
                  driver.get(URL)
                  
                  input_field = driver.find_element_by_name('ipID')
                  input_field.send_keys('0000000000')
                  driver.find_element_by_id('idSubmit').click()
                  
                  wait = WebDriverWait(driver, 10)
                  wait.until(EC.element_to_be_clickable((By.NAME, 'ipResponse')))
                  
                  print(driver.page_source)

                  这篇关于Selenium/Python - 提交表单后提取动态生成的 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                  <small id='NOcv9'></small><noframes id='NOcv9'>

                    <bdo id='NOcv9'></bdo><ul id='NOcv9'></ul>

                          <tbody id='NOcv9'></tbody>

                          • <tfoot id='NOcv9'></tfoot>
                          • <i id='NOcv9'><tr id='NOcv9'><dt id='NOcv9'><q id='NOcv9'><span id='NOcv9'><b id='NOcv9'><form id='NOcv9'><ins id='NOcv9'></ins><ul id='NOcv9'></ul><sub id='NOcv9'></sub></form><legend id='NOcv9'></legend><bdo id='NOcv9'><pre id='NOcv9'><center id='NOcv9'></center></pre></bdo></b><th id='NOcv9'></th></span></q></dt></tr></i><div id='NOcv9'><tfoot id='NOcv9'></tfoot><dl id='NOcv9'><fieldset id='NOcv9'></fieldset></dl></div>

                            <legend id='NOcv9'><style id='NOcv9'><dir id='NOcv9'><q id='NOcv9'></q></dir></style></legend>