error with Firefox Binary 'The browser appears to have exited'

2015-04-12 Thread mahmoud alnafei
I have problem with selenium and Firefox when i run my code below:

from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
import urllib2,cookielib
import re
from pyvirtualdisplay import Display
import urllib
import urllib2
import httplib2
from os import system

display = Display(visible=0, size=(800, 600))
display.start()

name = 'test'
driver = webdriver.Firefox()
driver.get("http://example.com";)
driver.switch_to_default_content()
inputElement = driver.find_element_by_name("name")
inputElement.send_keys(name)
inputElement.submit()
print "Please wait for 5s to get results.."
content = driver.page_source.encode("utf-8")
html = str(content)
soup = BeautifulSoup(html)
print soup
display.stop()
driver.close()




And i get this error:

Exception in thread command9:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/threading.py", line 551, in 
__bootstrap_inner
self.run()
  File "/usr/local/lib/python2.7/threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
  File "plugins/help_plugin.py", line 165, in handler_search
search_number_ar(type, source, parameters)
  File "plugins/test.py", line 230, in search_test
driver = webdriver.Firefox()
  File 
"/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/webdriver.py",
 line 59, in __init__
self.binary, timeout),
  File 
"/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/extension_connection.py",
 line 47, in __init__
self.binary.launch_browser(self.profile)
  File 
"/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py",
 line 66, in launch_browser
self._wait_until_connectable()
  File 
"/usr/local/lib/python2.7/site-packages/selenium-2.45.0-py2.7.egg/selenium/webdriver/firefox/firefox_binary.py",
 line 100, in _wait_until_connectable
raise WebDriverException("The browser appears to have exited "
WebDriverException: Message: The browser appears to have exited before we 
could connect. If you specified a log_file in the FirefoxBinary constructor, 
check it for details.


my code running in vps and i use selenium-2.45.0 and firefox-38.0b3 . I try 
alot of ways to solve my problem but nothing working with me. I try to update 
selenium and i try to downgrade firefox and alot of solution.

Just to know when i run my code for the first time it work but when i run it 
again it show me the above error.
I have Python2.7 .

I hope someone help me.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Mahmoud Abdel-Fattah
Thanks ChrisA a lot.

I just tried what you said, but I got an error, here's what I tried :
item['name'] = hxs.select('//div[@id="center-main"]/h1/text()').extract()[0]
author_brand = re.match(r'^[.*] - (.*)$', item['name'], re.I|re.S|re.M)
item['author_brand'] = author_brand.group(2) if type(author_brand) != None
else ''


And I'm getting the following error :
AttributeError: 'NoneType' object has no attribute 'group'


Thanks again :)


On Sun, Apr 15, 2012 at 12:35 AM, Zero Piraeus  wrote:

> :
>
> > 1. How can I write the following code in easier way in Python ?
> > if len(item['description']) > 0:
> > item['description'] = item['description'][0]
> > else:
> > item['description'] = ''
>
> Assuming item['description'] is a string, all you need is
>
> >>> item['description'] = item['description'][:1]
>
> Read up on string/sequence slicing if it isn't clear why that works.
>
> > 2. How can I check if this variable defined or not, in PHP I can use
> > isset();, in other way, how can I make the following syntax in Python ?
> > $variable = isset($array['element']) ? true : false;
>
> For that example:
>
> >>> variable = 'element' in array
>
> In both cases, a more general solution would be more complex ... note
> that in your second question, you're not actually testing whether a
> variable is set, but whether a dict has a value for a particular key.
>
>  -[]z.
>
-- 
http://mail.python.org/mailman/listinfo/python-list


[newbie questions] if conditions - if isset - if empty

2012-04-14 Thread Mahmoud Abdel-Fattah
Hello,

I'm coming from PHP background ant totally new to Python, I just started
using scrapy, but has some generic question in python.

1. How can I write the following code in easier way in Python ?
if len(item['description']) > 0:
item['description'] = item['description'][0]
else:
item['description'] = ''


In PHP I can write it as follows :
$item['description'] = (len(item['description']) > 0)
? item['description'][0] : '';

 So, is there similar way in Python ?



2. How can I check if this variable defined or not, in PHP I can use
isset();, in other way, how can I make the following syntax in Python ?
$variable = isset($array['element']) ? true : false;



Thanks a lot,
Mahmoud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: easy question, how to double a variable

2009-09-22 Thread Mahmoud Abdelkader
http://codingforums.com/showthread.php?s=e26b8b0aabc69745ef24a855b1a0fc83&t=177529

It seems that this dude really is looking for how to double a variable...

"""
hi looking for help catching up in a class and overall to get me better than
i am now. I can pay you by the week or per hour.

everything can be done by email i will ask you questions and send you simple
questions like:

how to double a variables value i.e: def double(x):
return (x * 2)

ect. you can post here or send me an email at ***...@aol.com
"""

On Tue, Sep 22, 2009 at 9:01 AM, Mel  wrote:

> Tim Roberts wrote:
>
> > daggerdvm  wrote:
> >>
> >>carl banks.you are a dork
> >
> > What are you, eleven years old?
> >
> > Look, you asked us to answer for you what is CLEARLY a homework question.
> > It is unethical for you to ask that, and it is unethical for us to answer
> > it.
>
> Forget ethical.  We can do his homework for him, we can perhaps pass exams
> for him, maybe graduate for him, and then with our luck, he'll get a job in
> our office and we get to do his work for him.
>
>Mel.
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating my own logwatch in python

2009-07-17 Thread Mahmoud Abdelkader
A few code critiques:
 -  Your code is not very help friendly because it can not be run, so I have
to deadlist debug it.
 -  There are various syntax errors in the code:
- for example: file is not defined when you invoke tail(file)
 -  You are overshadowing a built-in type 'file' by that name, which is
confusing. PEP 8 states that if you want to use a keyword, the practice is
to put an underscore after it. So, it should become file_
 -  Getopt is very old and should not be used. You should use the better,
readable, optparse
 -  That while loop will consume 99% CPU because of the infinite loop
 -  line = file.readline() is guaranteed to return a newline OR an empty
string ONLY when an EOF is encountered since you're not specifying the
optional maximum read byte size. This means that all your characters are
strings. So, why do you explicitly convert each character to a string and
separate each character by a space? (line 18)
 - Line 19 will always return 0 because of line 18
 - Line 19->22 are completely redundant, since readline is guaranteed to
give you ONE line. You should just do if "uccess" in logString: ...

Hope this helps,
mahmoud mack abdelkader
http://blog.mahmoudimus.com/



On Fri, Jul 17, 2009 at 5:58 PM, LoD MoD  wrote:

> I am trying to fabricate a logwatch-type script in Python and I'm having
> some trouble.What happens with the following code is that it prints to the
> screen but the if condition on line 22 never gets executed.
>
> http://pastie.org/549975
>
> Any suggestions are appreciated.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal: add setresuid() system call to python

2009-07-17 Thread Mahmoud Abdelkader
Why don't you write a python extension module? This is a perfect opportunity
for that.

--
mahmoud mack abdelkader
http://blog.mahmoudimus.com/



On Fri, Jul 17, 2009 at 4:01 PM,

> wrote:

> Hello,
>
> Historically, I have used scripting languages like python for typical
> uses, but they tend to not fare very well at system programming; for
> close interfacing with the operating system, I'm often forced to use a
> language like C.  This is undesirable to me.
>
> I do not think this has to be the case; I see no reason why a
> scripting language can't implement more of the system call API, at the
> risk of having some OS-dependent modules.  I would actually like to
> see more network servers written in scripting languages, as they
> neatly avoid buffer overflow and integer overflow issues with no extra
> effort.
>
> One BIG roadblock to doing this is when they can't manage to drop
> permissions properly.
>
> I am suggesting that the setresuid function be added to python,
> perhaps in the OS module, because it has the clearest semantics for
> manipulating user ids.  The reason why is best described in the
> following paper:
>
> http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf<http://www.eecs.berkeley.edu/%7Edaw/papers/setuid-usenix02.pdf>
>
> One argument against this is that it is not specified by POSIX, and
> thus might be dismissed as "implementation dependent".
>
> However, as the paper above demonstrates, even though the setuid
> system call is defined by POSIX, it already has system-dependent
> behavior.  POSIX provides for at least two different behaviors of the
> setuid call, and even more if you consider that it leaves what
> constitutes "appropriate privileges" up to the OS kernel.
>
> I humbly propose that python implement all the routines necessary to
> securely drop privileges, to enable construction of network daemons
> that might need to drop privileges from root to some non-root userid
> (e.g. mail transfer agents, or POP/IMAP servers).
>
> Furthermore, where there are multiple system calls to achieve this
> effect, it should implement the ones with the clearest semantics, and
> setresuid fits that bill.  To see what an utter mess the uid-manipulation
> routines are in, I refer you once again to this paper, as the situation
> is too complicated to describe in this email:
>
> http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf<http://www.eecs.berkeley.edu/%7Edaw/papers/setuid-usenix02.pdf>
>
> Opinions?
>
> Best,
> Travis
> --
> Obama Nation | My emails do not have attachments; it's a digital signature
> that your mail program doesn't understand. |
> http://www.subspacefield.org/~travis/<http://www.subspacefield.org/%7Etravis/>
> If you are a spammer, please email j...@subspacefield.org to get
> blacklisted.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


A multi-threaded file searcher for processing large text files

2009-07-17 Thread Mahmoud Abdelkader
 the worker threads
should set the stop conditions. A glaring hole leading from this is if the
blocking_timeout is set to something like 1second and by the time a user
attempts to iterate over the results, the worker threads will prematurely
stop processing.

Speaking of stop processing, should self._stop_processing be a conditional
variable. Right now it's a boolean, and I think that's pretty hacky. I don't
like the StopIteration stop condition, maybe someone has a better
suggestion?

A future modification I'm looking for is to launch multiple threads that
process different parts of the file (different chunks) and return their
results, probably indexed by their chunk offset. Then I can iterate over
that sequentially. I think that would be a trivial parallel optimization.

Thoughts? Comments?

Thanks very much,

Mahmoud Abdelkader
mahm...@linux.com
http://blog.mahmoudimus.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: one-time factory in python for an experienced java guy

2009-07-14 Thread Mahmoud Abdelkader
What Paul was trying to elaborate on is that have your customers or whomever
will use this implement their own generator protocol to generate whatever
number format they need. Paul just gave you an example with
itertools.count(), where it is an infinite generator that yields count+1
every time.

Read up on the iterator protocol, have your customers pass in a generator to
establish their own formats.
http://docs.python.org/library/stdtypes.html#iterator-types

This is much more elegant than AbstractCustomerRandomFormatGenerator..etc
which is what the reference to "erase everything from Java" is attempting to
relate.

--
mahmoud mack abdelkader
python powered
http://blog.mahmoudimus.com/
mahm...@linux.com


On Tue, Jul 14, 2009 at 10:55 AM, phonky  wrote:

> Thanks Paul,
>
>  Ugh, just forget everything you ever knew about java.  Do some Zen
>> exercises to erase your mind.  Then read a Python tutorial as if
>> you're starting from nothing.
>>
>
> Yeah, surely right, but easier said than done...
> I'm working on it.
>
> Taking your example.
>
> import itertools
>
>class Account(object):
>   def __init__(self, holder, gen=itertools.count()):
>  self.__accountnumber = gen.next()
>
> If you consider my python illiteracy,
>
> "itertools.count(): Make an iterator that returns consecutive integers
> starting with n"
>
> to me that sounds like that solves the increment issue, but what about
> future modules wanting to plug in a different
> numbering format, e.g. 205434.1234 or whatever?
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list