【问题标题】:Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'strict-dynamic'拒绝执行内联事件处理程序,因为它违反了以下内容安全策略指令:“script-src 'strict-dynamic'
【发布时间】:2021-01-09 12:16:00
【问题描述】:

我正面临拒绝执行内联事件处理程序的错误,因为它违反了以下内容安全策略指令:“script-src 'strict-dynamic' ,同时执行以下代码。

我正在使用下载的 selenium webdriver for chrome(版本:87.0.4280.88)

我的 python 版本 3.5.0。硒版本 3.141.0。愿任何人都可以在这个问题上提供帮助。有时问题没有出现。

还验证了该网页未使用任何 CSP 标头。 任何人提供建议我们是否可以从 selenium webdriver 禁用此验证?以及是否是推荐的方法?

使用的代码:

            import json
            import re
            import imaplib
            import base64
            import os
            import email
            import pandas as pd
            from bs4 import BeautifulSoup
            from requests import get
            from selenium import webdriver
            from selenium.webdriver.common.keys import Keys
            import time
            from selenium.webdriver.common.by import By
            from selenium.webdriver.support.ui import WebDriverWait
            from selenium.webdriver.support import expected_conditions as EC
            from selenium.common.exceptions import NoSuchElementException
            from selenium.common.exceptions import ElementNotVisibleException
            from selenium.common.exceptions import ElementNotSelectableException
            from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
            from selenium.webdriver.support.ui import Select
            import xlrd
            import datetime


            try:
                urllogin = 'https://www.phptravels.net/supplier'
                my_web_form = get(urllogin).content
                soup = BeautifulSoup(my_web_form, 'html.parser')

                path = r'C:/Users/suresh.n/python/Files/chromedriver.exe' #make sure you insert the path to your driver here!
                options = webdriver.ChromeOptions()
                options.add_argument("--start-maximized")
                options.add_argument("--user-data-dir=C:/Users/suresh.n/AppData/Local/Google/Chrome/User Data Copy/")
                options.add_argument("--disable-gpu")
                
                driver = webdriver.Chrome(path,chrome_options=options)
                
                driver.get(urllogin)
                
                driver.find_element_by_name("email").send_keys('supplier@phptravels.com')
                driver.find_element_by_name("password").send_keys('demosupplier')
                
                driver.find_element_by_xpath("/html/body/div[2]/form[1]/button").click()
                
                time.sleep(3)
                    
            finally:    
                driver.quit()

【问题讨论】:

    标签: python-3.x google-chrome selenium-chromedriver


    【解决方案1】:

    突然停止出现上述错误。不确定确切的原因。不过现在解决了。

    仅获取 selenium chrome 驱动程序蓝牙 adator 消息的消息。

    【讨论】:

      猜你喜欢
      • 2023-02-25
      • 2013-03-17
      • 2013-07-13
      • 1970-01-01
      • 1970-01-01
      • 2020-09-26
      • 2019-10-18
      • 1970-01-01
      • 2012-09-17
      相关资源
      最近更新 更多