Re: Converting getCSS Count Code from java to python

2011-02-17 Thread SMERSH009
On Feb 2, 7:03 am, Duncan Booth duncan.bo...@invalid.invalid wrote:
 Stefan Behnel stefan...@behnel.de wrote:
  You are using Selenium RC here. I have no idea if there is a Python
  API to it or what that API looks like. The rest is just trivial code
  that you can map 1:1 to Python:

       def count_css_matches(css_locator):
           java_script_code = '''
               var cssMatches = eval_css(%s, window.document);
               cssMatches.length;''' % css_locator
           return int(selenium.getEval(java_script_code))

  Although I'd simplify the JavaScript code somewhat to make it a plain
  expression.

 You also need somewhere:

     from selenium import selenium

 and in Python the method that is needed is selenium.get_eval(...)

 --
 Duncan Boothhttp://kupuguy.blogspot.com

On Feb 2, 7:03 am, Duncan Booth duncan.bo...@invalid.invalid wrote:
 Stefan Behnel stefan...@behnel.de wrote:
  You are using Selenium RC here. I have no idea if there is a Python
  API to it or what that API looks like. The rest is just trivial code
  that you can map 1:1 to Python:

   def count_css_matches(css_locator):
   java_script_code = '''
   var cssMatches = eval_css(%s, window.document);
   cssMatches.length;''' % css_locator
   return int(selenium.getEval(java_script_code))

  Although I'd simplify the JavaScript code somewhat to make it a plain
  expression.

 You also need somewhere:

 from selenium import selenium

 and in Python the method that is needed is selenium.get_eval(...)

 --
 Duncan Boothhttp://kupuguy.blogspot.com

Hi All,
Thanks a lot for the help. I feel like I've made some progress, yet I
am still stuck with the following error when I try to
print self.count_css_matches('css=[id=listGuests]')
I've also included the Selenium code below. Any further help would be
appreciated.

Traceback (most recent call last):
  File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
27, in test_untitled
print self.count_css_matches('css=[id=listGuests]')
  File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
17, in count_css_matches
return int(selenium.get_eval(self, java_script_code))
TypeError: unbound method get_eval() must be called with selenium
instance as first argument (got Untitled instance instead)

--


from selenium import selenium
import unittest, time
from datetime import datetime

class Untitled(unittest.TestCase):
def count_css_matches(self, css_locator):
java_script_code = '''
var cssMatches = eval_css(%s, window.document);
cssMatches.length;''' % css_locator
return int(selenium.get_eval(self, java_script_code))
#return int(selenium.getEval(java_script_code))

def setUp(self):
self.verificationErrors = []
self.selenium = selenium(localhost, 4445, *chrome, http://
www.guestlistnation.com/)
self.selenium.start()



def test_untitled(self):
sel = self.selenium
sel.window_maximize()
sel.open(/Events.aspx?Location=SAN FRANCISCO)
 
sel.click(css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails'])
sel.wait_for_page_to_load(3)

print self.count_css_matches('css=[id=listGuests]')

if __name__ == __main__:
unittest.main()


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting getCSS Count Code from java to python

2011-02-17 Thread SMERSH009
On Feb 17, 9:51 pm, Stefan Behnel stefan...@behnel.de wrote:
 SMERSH009, 17.02.2011 22:46:



  am still stuck with the following error when I try to
  print self.count_css_matches('css=[id=listGuests]')
  I've also included the Selenium code below. Any further help would be
  appreciated.

  Traceback (most recent call last):
     File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
  27, in test_untitled
       print self.count_css_matches('css=[id=listGuests]')
     File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
  17, in count_css_matches
       return int(selenium.get_eval(self, java_script_code))
  TypeError: unbound method get_eval() must be called with selenium
  instance as first argument (got Untitled instance instead)

  --

  from selenium import selenium
  import unittest, time
  from datetime import datetime

  class Untitled(unittest.TestCase):
       def count_css_matches(self, css_locator):
           java_script_code = '''
               var cssMatches = eval_css(%s, window.document);
               cssMatches.length;''' % css_locator
           return int(selenium.get_eval(self, java_script_code))
           #return int(selenium.getEval(java_script_code))

 You want to use self.selenium here, not selenium.

 Stefan

       def setUp(self):
           self.verificationErrors = []
           self.selenium = selenium(localhost, 4445, *chrome, http://
 www.guestlistnation.com/)
           self.selenium.start()

       def test_untitled(self):
           sel = self.selenium
           sel.window_maximize()
           sel.open(/Events.aspx?Location=SAN FRANCISCO)

  sel.click(css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails'])
           sel.wait_for_page_to_load(3)

           print self.count_css_matches('css=[id=listGuests]')

  if __name__ == __main__:
       unittest.main()



Wow-- you guys rock --big time! :))
Here is the final code with a working examples:


from selenium import selenium
import unittest, time
from datetime import datetime

class Untitled(unittest.TestCase):
def count_css_matches(self, css_locator):
java_script_code = '''
var cssMatches = eval_css(%s, window.document);
cssMatches.length;''' % css_locator
return self.selenium.get_eval(java_script_code)


def setUp(self):
self.verificationErrors = []
self.selenium = selenium(localhost, 4445, *chrome, http://
www.guestlistnation.com/)
self.selenium.start()

def test_untitled(self):
sel = self.selenium
sel.window_maximize()
sel.open(/Events.aspx?Location=SAN FRANCISCO)

 
sel.click(css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails'])
sel.wait_for_page_to_load(3)

print self.count_css_matches([id='listGuests']  option) #
prints number of options in dropdown with 'id=listGuests'
print self.count_css_matches(*) #prints all on page
if __name__ == __main__:
unittest.main()




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Converting getCSS Count Code from java to python

2011-02-17 Thread SMERSH009
On Feb 17, 10:25 pm, SMERSH009 smersh0...@gmail.com wrote:
 On Feb 17, 9:51 pm, Stefan Behnel stefan...@behnel.de wrote:



  SMERSH009, 17.02.2011 22:46:

   am still stuck with the following error when I try to
   print self.count_css_matches('css=[id=listGuests]')
   I've also included the Selenium code below. Any further help would be
   appreciated.

   Traceback (most recent call last):
      File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
   27, in test_untitled
        print self.count_css_matches('css=[id=listGuests]')
      File D:\Temp\1TestingApps\Selenium\Scripts\SevPractice.py, line
   17, in count_css_matches
        return int(selenium.get_eval(self, java_script_code))
   TypeError: unbound method get_eval() must be called with selenium
   instance as first argument (got Untitled instance instead)

   --

   from selenium import selenium
   import unittest, time
   from datetime import datetime

   class Untitled(unittest.TestCase):
        def count_css_matches(self, css_locator):
            java_script_code = '''
                var cssMatches = eval_css(%s, window.document);
                cssMatches.length;''' % css_locator
            return int(selenium.get_eval(self, java_script_code))
            #return int(selenium.getEval(java_script_code))

  You want to use self.selenium here, not selenium.

  Stefan

        def setUp(self):
            self.verificationErrors = []
            self.selenium = selenium(localhost, 4445, *chrome, http://
  www.guestlistnation.com/)
            self.selenium.start()

        def test_untitled(self):
            sel = self.selenium
            sel.window_maximize()
            sel.open(/Events.aspx?Location=SAN FRANCISCO)

   sel.click(css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails'])
            sel.wait_for_page_to_load(3)

            print self.count_css_matches('css=[id=listGuests]')

   if __name__ == __main__:
        unittest.main()

 Wow-- you guys rock --big time! :))
 Here is the final code with a working examples:

 from selenium import selenium
 import unittest, time
 from datetime import datetime

 class Untitled(unittest.TestCase):
     def count_css_matches(self, css_locator):
         java_script_code = '''
             var cssMatches = eval_css(%s, window.document);
             cssMatches.length;''' % css_locator
         return self.selenium.get_eval(java_script_code)

     def setUp(self):
         self.verificationErrors = []
         self.selenium = selenium(localhost, 4445, *chrome, 
 http://www.guestlistnation.com/;)
         self.selenium.start()

     def test_untitled(self):
         sel = self.selenium
         sel.window_maximize()
         sel.open(/Events.aspx?Location=SAN FRANCISCO)

 sel.click(css=[id='EventDates_ctl00_NestedEvents_ctl01_btnDetails'])
         sel.wait_for_page_to_load(3)

         print self.count_css_matches([id='listGuests']  option) #
 prints number of options in dropdown with 'id=listGuests'
         print self.count_css_matches(*) #prints all on page
 if __name__ == __main__:
     unittest.main()

oops, forgot to put back the int conversion!

def count_css_matches(self, css_locator):
java_script_code = '''
var cssMatches = eval_css(%s, window.document);
cssMatches.length;''' % css_locator
return int(self.selenium.get_eval(java_script_code))
-- 
http://mail.python.org/mailman/listinfo/python-list


Converting getCSS Count Code from java to python

2011-01-31 Thread SMERSH009
Hi, I'd love some help converting this code to the python equivalent:

private int getCSSCount(String aCSSLocator){
String jsScript = var cssMatches = eval_css(\%s\,
window.document);cssMatches.length;;
return Integer.parseInt(selenium.getEval(String.format(jsScript,
aCSSLocator)));
}

http://www.eviltester.com/index.php/2010/03/13/a-simple-getcsscount-helper-method-for-use-with-selenium-rc/

Thanks for the help
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Formatting Results so that They Can be Nicely Imported into a Spreadsheet.

2007-08-05 Thread SMERSH009
On Aug 4, 8:25 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 On Aug 4, 9:21?pm, Jim Langston [EMAIL PROTECTED] wrote:



  [EMAIL PROTECTED] wrote in message

 news:[EMAIL PROTECTED]

   On Aug 4, 6:35?pm, SMERSH009 [EMAIL PROTECTED] wrote:
   Hi All.
   Let's say I have some badly formatted text called doc:

   doc=
   
   friendid
   Female

   23 years old

   Los Gatos

   United States
   friendid
   Male

   24 years old

   San Francisco, California

   United States
   

   How would I get these results to be displayed in a format similar to:
   friendid;Female;23 years old;Los Gatos;United States
   friendid;Male; 24 years old;San Francisco, California;United States

   The latter is a lot easier to organize and can be quickly imported
   into Excel's column format.

   Thanks Much,
   Sam

   d = doc.split('\n')

   f = [i.split() for i in d if i]

   g = [' '.join(i) for i in f]

   rec = []
   temprec = []
   for i in g:
  if i:
  if i == 'friendid':
  rec.append(temprec)
  temprec = [i]
  else:
  temprec.append(i)
   rec.append(temprec)

   output = [';'.join(i) for i in rec if i]

   for i in output: print i

   ##friendid;Female;23 years old;Los Gatos;United States
   ##friendid;Male;24 years old;San Francisco, California;United States

  also, I would suggest you use CSV format.

 Well, the OP asked for a specific format. One is not
 always at liberty to change it.

  CSV stands for Comma Seperated
  Variable and Excel can load such a sheet directly.

 And Excel can load the shown format directly also,
 just specify the delimiter.



  Instead of seperating using ; seperate using ,  Of course, this provides a
  problem when there is a , in a string.

 Which explains the popularity of using tabs as delimiters.
 The data deliverable specification I use at work
 uses the pipe character | which never appears as data
 in this particular application.

  Resolution is to quote the string.

 Which makes the file bigger and isn't necessary
 when tabs and pipes are used as delimiters.

  Being such, you can just go ahead and quote all strings.  So you would want
  the output to be:

  friendid,Female,23 years old,Los Gatos,United States
  friendid,Male,24 years old,San Francisco, California,United States

 Which I would do if I had a specification that
 demanded it or was making files for others. For my
 own use, I wouldn't bother as it's unnecessary work.



  Numbers should not be quoted if you wish to treat them as numeric and not
  text.

 A good reason not to use quotes at all. Besides which,
 Excel can handle that also.

Thanks for all your posts guys.
mensanator's was the most helpful, and I only ended up needing to use
a few lines from that code.
The only question that remains for me--and this is just for my
knowledge-- what does the if i mean in this code snippet?
f = [i.split() for i in d if i]
How is it helpful to leave a dangling if i? Why not just f =
[i.split() for i in d]?

And yes John, this was indeed a homework question. It was for my
daughter's preschool. You are going to help her ace her beginner
Python class! (No, this was not a homework question).

-- 
http://mail.python.org/mailman/listinfo/python-list


Formatting Results so that They Can be Nicely Imported into a Spreadsheet.

2007-08-04 Thread SMERSH009
Hi All.
Let's say I have some badly formatted text called doc:


doc=

friendid
Female

23 years old

Los Gatos

United States
friendid
Male

24 years old

San Francisco, California

United States


How would I get these results to be displayed in a format similar to:
friendid;Female;23 years old;Los Gatos;United States
friendid;Male; 24 years old;San Francisco, California;United States


The latter is a lot easier to organize and can be quickly imported
into Excel's column format.

Thanks Much,
Sam

-- 
http://mail.python.org/mailman/listinfo/python-list


Script that Navigates Page needs Javascript Functionality

2007-08-03 Thread SMERSH009
I have a script that navigates pages and scrapes the HTML source of
the page.
in order to view the results I need I need python to navigate to
this Javascript link:
javascript:__doPostBack('ctl00$cpMain$pagerTop','4')  This basically
translates into go to page 4.
I read the posts on this group, and from what I understand, the
functionality I need is with simplejson? If so, what is the syntax i
would use to execute that Javascript?
Or am I completely off base with using simplejson altogether?


Thanks for the help
-Sam

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PYTHON PROGRAMMING HELP PLSSS !!

2007-08-03 Thread SMERSH009
On Aug 2, 6:24 pm, Dennis [EMAIL PROTECTED] wrote:
 HI All,
 i am a 4th year business student and i took web design online course
 for fun however i did not see that last 2 chapters were python
 programming.This has no relevance to my major nor does it have any
 contribution to my degree. My fun turned out to be my nightmare since
 i literally can not grasp the main idea like other computer science
 students. To sum up , i need help with the following code, please do
 not send me emails telling me that outside class help is not provided
 or etc, this is not my major related course and this might also affect
 my graduation date.
 This is the working sample program 
 ;http://cmpt165.cs.sfu.ca/~ggbaker/examples/chequebook.html
 If interested please email me, i am ready to make it up for your time
 that you spend to get me out of this mess.
 thanks

What exactly do you need done? Be more specific instead of just
pasting a link to a page
Also, you might want to state how much you are willing to 'compensate'
someone.
Maybe you will get more responses this way :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Email

2007-08-03 Thread SMERSH009
On Aug 3, 9:47 am, Rohan [EMAIL PROTECTED] wrote:
 On Aug 2, 1:06 pm, Laurent Pointal [EMAIL PROTECTED] wrote:



  Rohan wrote:
   I was wondering if there could be an arrangement where a file could be
   attached and send as an email.
   For ex
   f = open(add.txt,w)
   f.write('python')
   f.close()

   Now I would like to send an email with add.txt as an attachment, is it
   possible ?
   some one give me a pointer towards this.

  You can use iMailer as an example script to get parts:

 http://nojhan.free.fr/article.php3?id_article=22

  A+

  Laurent.

 Laurent the link you gave me is in a language unknown to me if you
 have anything that expalains in english, then let me know.
 thanks

Did you try Google translate?  Here is the tiny url of the page you
wanted translated http://tinyurl.com/3xlcmc

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Website data-mining.

2007-08-03 Thread SMERSH009
On Aug 3, 7:50 pm, Coogan [EMAIL PROTECTED] wrote:
 Hi--

 I'm using Python for the first time to make a plug-in for Firefox.
 The goal of this plug-in is to take the source code from a website
 and use the metadata and body text for different kinds of analysis.
 My question is: How can I retrieve data from a website? I'm not even
 sure if this is possible through Python. Any help?

 nieu

How about this? it will fetch the HTML source of the page.

import datetime, time, re, os, sys, traceback, smtplib, string,\
urllib2, urllib, inspect
from urllib2 import build_opener, HTTPCookieProcessor, Request
opener = build_opener(HTTPCookieProcessor)
from urllib import urlencode

def urlopen2(url, data=None, user_agent='urlopen2'):
Opens Our URLS 
if hasattr(data, __iter__):
data = urlencode(data)
headers = {'User-Agent' : user_agent}
return opener.open(Request(url, data, headers))

###TESTCASES START HERE###
def publishedNotes():
page = urlopen2(http://www.yourURL.com;, ())
pageRead = page.read()
print pageRead

if __name__ == '__main__':
publishedNotes()

sys.exit()

-- 
http://mail.python.org/mailman/listinfo/python-list