硒改变火狐浏览器语言python的Mac [英] Selenium change firefox browser language python mac
问题描述
我正在写一个程序,进入几个搜索条件谷歌 - 并检索我的网页的排名。我想知道我的几个不同的国家SERP的排名。我已经解决了IP地址的问题。但现在我看到,当给我一个SERP的时候,谷歌正在考虑我的浏览器的语言。为了更接近我的网页在一个国家的真实排名(我说更接近,因为我也看到SERP依赖于搜索历史),我必须使用一个网络浏览器与本国语言本人感兴趣。
手动更改Firefox中的语言非常困难 - 事实上,您必须安装几种不同的语言版本(我还阅读了关于安装语言包 - 但不确定这是否与Firefox 12相关)。我不知道如何让硒选择正确的Firefox版本。
我很难理解需要做什么:当启动<$ c $时,是否需要指定使用哪个firefox安装/版本selenium c> web driver.firefox()。或者可以通过更改firefox配置文件来确定浏览器语言。
我花了一些时间看着个人资料部分 - 并发现部分 同样的答案后似乎已经解决了这个问题 - 但我不知道这个语言,而且我很难理解实际正在做什么。 我知道有一个附加组件到Firefox之间的语言版本之间进行切换(您必须首先安装所需的不同语言版本的Firefox) - 假设settings选项提到更改general.useragent。本地偏好我认为这是一个可以更改的配置文件设置 - 但附加组件需要重新启动浏览器,当你改变语言 - 所以.. 我无法在配置文件设置中找到关于general.useragent.local的任何信息。 任何一个给我一个正确的方向的点将是我的一天! 编辑: 好的,我必须同意,也许这不是解决这个问题的最好方法,但会回答你所需要的东西来自selenium的 pydocs可用这里 I've spent 3 hours trying to find a solution to this problem, and I'm so far from an answer I feel like I have to ask. (I've found similar posts - below is an explanation of why I'm asking despite finding these posts) I'm writing a program that enters several search terms into google - and retrieves the ranking of my page. I want to know my ranking for several different country SERP's. I've gotten the issue with ip address solved. But now I see that google is factoring in the language of my browser when giving me a SERP. In order to get closer to the true rank of my page in a country ( I say closer because I've also seen that the SERP depends on search history) I have to use a web browser with a language native to the country I'm interested in. Changing the language in firefox manually is difficult - as a matter of fact you have to install several different language version (I've also read about installing language packs - but unsure if this is relevant for firefox 12). I don't have a clue about how to get selenium to choose the right firefox version. I'm having a hard time understanding what needs to be done: Do I have to specify which firefox installation / version selenium is suppose to use when launching I've spent some time looking into the profile part - and found partial evidence (original post) although I can't find any reference to language in the profile files. The answer in the same post seems to have solved the problem - but I don't know the language and I'm having trouble understanding what's actually being done. I know there's an add-on to firefox for changing between the language versions (you have to first install the different language versions of firefox that you want) - Given that the settings option mentions changing "general.useragent.local preference" I'm thinking it's a profile setting that can be changed - but the add-on requires a re-start of the browser when you change the language - so.. I can't find anything about general.useragent.local in the profile settings. Any one giving me a point in the right direction would be making my day! EDIT:
Forgot to mention - I only know python - so that's why I wrote python in the title Ok, I have to agree that perhaps this isnt the best way to approach this problem but will answer what you need The pydocs are available here 这篇关于硒改变火狐浏览器语言python的Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
忘了提及 - 我只知道python - 所以这就是为什么我写了python的标题
import webdriver
来自selenium.webdriver.firefox.firefox_binary导入FirefoxBinary
inary = FirefoxBinary('path / to / binary')
profile = webdriver.FirefoxProfile()
profile.add_extension(' path / to / xpi')#XPI需要在磁盘上,而不是从AMO
profile.set_preference('general.useragent.local','<输入你的值')下载
驱动程序= webdriver.Firefox(firefox_binary =二进制,firefox_profile =配置文件)
#继续您想要的
web driver.firefox().
Or is it possible to determine the browser language by changing the firefox profile. from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path/to/binary')
profile = webdriver.FirefoxProfile()
profile.add_extension('path/to/xpi') #XPI needs to be on disk and not downloaded from AMO
profile.set_preference('general.useragent.local','<enter your value')
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=profile)
# Carry on with what you want