我正在尝试使用 python 结合 seleniumwire 创建一个脚本在其中实现 poxies。该脚本有时可以正常工作,但大多数时候即使 status_code 为 200,也会显示错误日志详细信息。我希望删除这些日志详细信息。脚本中硬编码的 IP 地址取自免费代理站点,因此目前可能没有任何用处。
这就是我正在尝试的:
from seleniumwire import webdriver
URL = 'https://www.zillow.com/Houston,-TX/houses/'
options = {
'mitm_http2': False,
'proxy': {'https': f'https://136.226.33.115:80'}
}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.get(URL)
assert driver.requests[0].response.status_code==200
post_links = [i.get_attribute("href") for i in driver.find_elements_by_css_selector("article[role='presentation'] > .list-card-info > a.list-card-link")]
for individual_link in post_links:
driver.get(individual_link)
assert driver.requests[0].response.status_code==200
post_title = driver.find_element_by_css_selector("h1").text
print(post_title)
driver.quit()
这是我可以在控制台中看到的错误日志详细信息类型:
127.0.0.1:55825: request
-> HTTP protocol error in client request: Server disconnected
127.0.0.1:55967: request
-> HTTP protocol error in client request: Server disconnected
127.0.0.1:64891: request
-> HTTP protocol error in client request: Server disconnected
127.0.0.1:61466: request
-> HTTP protocol error in client request: Server disconnected
127.0.0.1:51332: request
-> HTTP protocol error in client request: Server disconnected
127.0.0.1:52783: request
-> HTTP protocol error in client request: Server disconnected
How can I force the script not to print those log details?
最佳答案
您可以通过以下代码行定义所需的日志错误级别:
options .add_argument('--log-level=3')
将此添加到您的选项
中。
log-level 属性设置最低日志级别。
有效值为 0 到 3:
信息=0,
警告=1,
LOG_ERROR = 2,
LOG_FATAL = 3。
默认为 0。
关于python - 无法强制脚本不在控制台中打印错误日志详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67970068/