使用python语言selenium库以及firefox编写使用user agent的程序
以下是使用Python和Selenium库来使用User-Agent的程序示例:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
# 设置Firefox选项
options = Options()
options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0')
# 启动Firefox浏览器
browser = webdriver.Firefox(firefox_options=options)
# 打开网址
browser.get('https://www.whatismybrowser.com/detect/what-is-my-user-agent')
# 获取User-Agent
user_agent = browser.find_element_by_css_selector('#detected_value').text
print(user_agent)
# 关闭浏览器
browser.quit()
这个程序使用了Firefox浏览器,并且设置了一个自定义的User-Agent,然后打开了whatismybrowser.com网址来检查User-Agent是否生效。最后,程序获取了检测到的User-Agent并输出到控制台,最后关闭了浏览器。
原文地址: https://www.cveoy.top/t/topic/pWe 著作权归作者所有。请勿转载和采集!