如何在 selenium python 中设置设备内存?
How can i set device memory in selenium python?
正在做一些测试并将它们与真实浏览器与 selenium 进行比较:
https://bot.sannysoft.com/
我的 webdriver 上的属性之一是 CHR_MEMORY IS FALSE
它存在于真实的浏览器中,有人知道我该如何更改它吗?
CHR_MEMORY FAIL
{}
您需要指定 navigator.deviceMemory
和 navigator.userAgent
看看这个example 基于 selenium
此外,这是我对剧作家的态度:
import re
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.add_init_script("""
Object.defineProperty(navigator, 'deviceMemory', {
get: () => 8
});
Object.defineProperty(navigator, 'userAgent', {
get: () => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
});
""")
page.goto('https://bot.sannysoft.com')
html = page.content()
status = 'failed'
if match := re.search('CHR_MEMORY<\/td><td class="(.*?)"', html):
status = match.group(1)
print(status)
# Prints 'passed'
browser.close()
正在做一些测试并将它们与真实浏览器与 selenium 进行比较: https://bot.sannysoft.com/ 我的 webdriver 上的属性之一是 CHR_MEMORY IS FALSE 它存在于真实的浏览器中,有人知道我该如何更改它吗?
CHR_MEMORY FAIL
{}
您需要指定 navigator.deviceMemory
和 navigator.userAgent
看看这个example 基于 selenium
此外,这是我对剧作家的态度:
import re
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.add_init_script("""
Object.defineProperty(navigator, 'deviceMemory', {
get: () => 8
});
Object.defineProperty(navigator, 'userAgent', {
get: () => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
});
""")
page.goto('https://bot.sannysoft.com')
html = page.content()
status = 'failed'
if match := re.search('CHR_MEMORY<\/td><td class="(.*?)"', html):
status = match.group(1)
print(status)
# Prints 'passed'
browser.close()