首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >该网站似乎检测到了selenium,阻止了jquery并给出了PR_CONNECT_RESET_ERROR

该网站似乎检测到了selenium,阻止了jquery并给出了PR_CONNECT_RESET_ERROR
EN

Stack Overflow用户
提问于 2022-08-12 18:41:11
回答 1查看 92关注 0票数 0

我刚接触过Selenium,所以我很抱歉,如果这是个菜鸟的问题。

我正试图用Python和Selenium实现文档的自动生成。

当我使用自动firefox或chrome驱动程序时,在最后一步之后,即单击按钮“gerar2a or”(xpath = '//* @id=“btnGerarSegundaVia”),页面就会冻结,除了一个甚至无法正确加载的图标之外什么也不会显示。开发人员的工具中的网络选项卡中也有一些jquery错误。

另一件有趣的事情是,当您试图通过自动浏览器重新加载页面时,服务器将返回PR_CONNECT_RESET_ERROR。

在你的头上模仿这个问题:

  1. 打开一个普通浏览器和另一个自动驱动程序浏览器。
  2. 输入以下数据:

普通浏览器:

自动浏览器:

  1. 单击
  2. 按钮,查看正常浏览器和自动浏览器的不同输出:

  1. 和当您在自动浏览器上刷新页面时:

我只编写了自动浏览器的打开代码来测试一些选项,没有一个注释掉的代码解决了我的问题。

代码语言:javascript
运行
复制
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.firefox.options import Options


# profile_path = r'whatever'
# options = Options()
# PROXY_HOST = "12.12.12.123"
# PROXY_PORT = "1234"
# options.set_preference('profile', profile_path)
# options.set_preference("network.proxy.type", 1)
# options.set_preference("network.proxy.http", PROXY_HOST)
# options.set_preference("network.proxy.http_port", int(PROXY_PORT))
# options.set_preference("dom.webdriver.enabled", False)
# options.set_preference('useAutomationExtension', False)
# options.add_argument('--ignore-certificate-errors')

# desired_caps = DesiredCapabilities.FIREFOX.copy()
# desired_caps.update({'acceptInsecureCerts': True, 'acceptSslCerts': True})

driver = webdriver.Firefox()


driver.get('https://iptu.prefeitura.sp.gov.br/')

如果我不得不猜测的话,问题是站点检测到‘连接不安全’,因为Selenium控制浏览器,然后阻止服务器的响应,但是你们比我聪明,所以请HEEEELP

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-08-12 20:02:30

以下是插入captcha文本的点,然后单击按钮,它将带您到pdf页面:

代码语言:javascript
运行
复制
import undetected_chromedriver as uc

from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

browser = uc.Chrome()

url = 'https://iptu.prefeitura.sp.gov.br/'

browser.get(url) 

contrib_field = WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txtNumeroContribuinte']")))
contrib_field.send_keys('019.045.0170-2')

parcel_field = Select(WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='comboBoxParcela']"))))
parcel_field.select_by_index(7)

ex_field = WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='txtExercicio']")))
ex_field.send_keys('2022')

关于undetected_chromedriver包:https://pypi.org/project/undetected-chromedriver/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73338506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档