Closed vkudyushev closed 9 years ago
I don't understand the problem. Can you include a small script which shows the problem?
So, I'm sorry, forgotten about code sample...
Here is header and sample line text file, where taken display size:
agents,freqs
"Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0||1366, 768","0.0068"
the "||" is delemiter inside first colunm (user-agent and screen size together because numpy can work only with two lists - value and it's frequence). So, then I take random value from list, split value from first column and give splitted values by variables into their places into this code:
agents = open("user-agents.txt", "r")
csvReader = csv.reader(agents)
header = csvReader.next()
agentsIndex = header.index("agents")
freqsIndex = header.index("freqs")
coordList = []
coordList2 = []
for col in csvReader:
agent = col[agentsIndex]
freq = col[freqsIndex]
coordList.append(agent)
coordList2.append(freq)
itog = np.random.choice(coordList, p=coordList2)
itogs = itog.split("||")
display = Display(visible=1, size=(itogs[1]))
display.start()
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override",itogs[0])
...
This functions putted into a loop by def fuction(). And so, user-agents value work perfect and user-agent always overrides, but size of virtual display isn't work correctly with this code.
When I type something like this
...display = Display(visible=1, size=(1027, 768))
it's works correctly, but not with size value from my variable. It starts a display with width 1px and height 3px. My python version is 2.7
For bug reports try to include small and complete working programs. I transformed your program into a small working one, I added string to int conversion which was missing:
from pyvirtualdisplay import Display
itog="Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0||1366, 768"
itogs = itog.split("||")
s=itogs[1]
width,height=map(int,itogs[1].split(','))
display = Display(visible=1, size=(width,height))
display.start()
Wow! Works like a charm! You are magician! Thank a lot!
Whet I trying to pass display size from variable, that taken from text file, pyvirtual ignore it and starts dizplay with width 1px and height 3-6px When I print display size like (1366, 768) in same script in works perfect. So, I've also tried to replace quotes (' and ") fron variable, but it gives same result.