提问人:satiric-goose1563 提问时间:10/18/2023 更新时间:10/18/2023 访问量:76
网站页面缓冲,但不会使用 Selenium chromedriver 加载
Website page buffers but will not load with Selenium chromedriver
问:
我是 python 的新手,正在尝试编写一个程序来自动执行从纽约市政府网站获取数据的任务,以使我的日常工作更轻松一些,因为我每周重复一次左右。使用 selenium chromedriver,打开页面并输入搜索信息,但随后页面只是缓冲和缓冲,直到我收到错误消息
selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 300.000
当我在没有 chromedriver 的情况下尝试此任务并在 chrome 中自己完成时,页面会立即加载而不会出现问题。我不明白为什么页面无法使用 chromedriver 加载?
难道是该网站检测到硒并且不允许请求通过,即使我没有被拒绝访问该网站?
任何帮助将不胜感激!
到目前为止,我已经尝试过:
- 安装undetected_chromedriver
- 手动启用 headless=true,但也不确定它是否正确
- 将页面加载策略设置为 eager
- 降级到 Python 4.12.0
这些都无济于事,页面仍然只是缓冲区,直到收到超时消息
这是我的代码:
import setuptools
import selenium
from selenium import webdriver
import undetected_chromedriver as uc
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_experimental_option("excludeSwitches", ['enable-automation']);
if __name__ == '__main__':
driver = uc.Chrome(headless=True,use_subprocess=False)
options = Options()
options.add_experimental_option("detach", True)
options = Options()
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://a810-bisweb.nyc.gov/bisweb/PropertyProfileOverviewServlet?/")
driver.maximize_window()
boro2Select = Select(driver.find_element("id", "boro2"))
boro2Select.select_by_visible_text('Queens')
search_box = driver.find_element("name", "block").send_keys('2433')
search_box = driver.find_element("name", "lot").send_keys('27')
goButton = driver.find_element("name", "go3")
goButton.click()
我使用崇高的文本,如果有帮助,我在 Mac 上 chrome 版本 118.0.5993.70 (官方版本) (x86_64) Selenium 版本 4.12.0
答:
0赞
Payrfix
10/18/2023
#1
尝试从更简单的脚本开始(访问网站后复制粘贴脚本)。
from selenium import webdriver
from selenium.webdriver.support.ui import Select
if __name__ == '__main__':
driver = webdriver.Chrome()
driver.get("https://a810-bisweb.nyc.gov/bisweb/PropertyProfileOverviewServlet?/")
driver.maximize_window()
boro2Select = Select(driver.find_element("id", "boro2"))
boro2Select.select_by_visible_text('Queens')
search_box = driver.find_element("name", "block").send_keys('2433')
search_box = driver.find_element("name", "lot").send_keys('27')
goButton = driver.find_element("name", "go3")
goButton.click()
我正在使用的版本 硒 = 4.14.0 蟒蛇 = 3.10
评论
0赞
satiric-goose1563
10/19/2023
谢谢你的帮助。这个脚本是我启动的方式,运行它也不起作用。我为另一个纽约市政府网站编写了一个类似的基本脚本进行测试,它运行良好,所以我开始认为这个网站对硒或网络抓取有某种阻止。我不确定为什么它不起作用。这就是为什么我试图实施undetected_chromedriver和其他东西来隐藏我的硒。我被难住了
评论