LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-25-2015, 04:33 PM   #1
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Rep: Reputation: 60
Python (seleniumrequests)Class, Constructor, Method Not Working


Newbie question. I created a class:
Code:
class WP(seleniumrequests.PhantomJS):
    
                def __init__(self, wpurl='https://blah.org/download/release-archive/', bwppurl='https://blah.org/plugins/browse/popular/'):
                                self.wp=wpurl
                                self.bwpp=bwppurl
                def wpscaper(self):
                                wpjfetch=seleniumrequests.PhantomJS('../ms-tuesday/phantomjs/bin/phantomjs')
                                wpjfetch.get(self.wp)
                                wpsoup=BeautifulSoup(wpjfetch.page_source, 'lxml')
                def wppscaper(self):
                                wppjfetch=seleniumrequests.PhantomJS('../ms-tuesday/phantomjs/bin/phantomjs')
                                wppjfetch.get(self.bwpp)
                                wppsoup=BeautifulSoup(wpjfetch.page_source, 'lxml')
I am trying to understand why I cannot see any of my methods in where I would expect it to be:
Code:
goodies=WP()
goodies.wpscaper()
goodies.wpscaper.wpjfetch.page_source
goodies.wpscaper.wpsoup
What I see is:
Code:
goodies.wpscaper.im_class  goodies.wpscaper.im_func   goodies.wpscaper.im_self
and the same applies for:
Code:
goodies=WP()
goodies.wppscaper()
goodies.wppscaper.im_class  goodies.wppscaper.im_func   goodies.wppscaper.im_self
What gives ??

Last edited by metallica1973; 08-25-2015 at 04:48 PM.
 
Old 08-25-2015, 05:43 PM   #2
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,237

Rep: Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321Reputation: 5321
I can't tell. Post a transcript of a Python interpreter session.

Last edited by dugan; 08-26-2015 at 11:19 AM.
 
Old 08-25-2015, 08:43 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
I am no python guru (and probably wrong), but looking at the class definition it would seem your class call requires an argument??
 
Old 08-26-2015, 02:34 PM   #4
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
Thanks for the replies. I can see that the stuff works. For example, if I add a print statement to the functions such as:
Code:
class WP(seleniumrequests.PhantomJS):
    
                def __init__(self, wpurl='https://blah.org/download/release-archive/', bwppurl='https://blah.org/plugins/browse/popular/'):
                                self.wp=wpurl
                                self.bwpp=bwppurl
                def wpscaper(self):
                                wpjfetch=seleniumrequests.PhantomJS('../ms-tuesday/phantomjs/bin/phantomjs')
                                wpjfetch.get(self.wp)
                                wpsoup=BeautifulSoup(wpjfetch.page_source, 'lxml')
                                print (wpsoup)
                def wppscaper(self):
                                wppjfetch=seleniumrequests.PhantomJS('../ms-tuesday/phantomjs/bin/phantomjs')
                                wppjfetch.get(self.bwpp)
                                wppsoup=BeautifulSoup(wpjfetch.page_source, 'lxml')
                                print (wppsoup)
it prints exactly whats in wpsoup or wppsoup:
Code:
goodies=WP()
goodies.wpscaper()
<!DOCTYPE html>
<html dir="ltr" lang="en" xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11">
<meta charset="utf-8"/>
<!--
<meta property="fb:page_id" content="6427302910" />
-->
<meta content="7VWES_-rcHBcmaQis9mSYamPfNwE03f4vyTj4pfuAw0" name="google-site-verification"/>
blah blah blah blah..
goodies.wppscaper()
<!DOCTYPE html>
<html dir="ltr" lang="en" xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11">
<meta charset="utf-8"/>
<!--
<meta property="fb:page_id" content="6427302910" />
-->
<meta content="7VWES_-rcHBcmaQis9mSYamPfNwE03f4vyTj4pfuAw0" name="google-site-verification"/>
blah blah blah blah..
Additonal Info:
Code:
In [180]: dir(goodies.wpscaper)
Out[180]: 
['__call__',
 '__class__',
 '__cmp__',
 '__delattr__',
 '__doc__',
 '__format__',
 '__func__',
 '__get__',
 '__getattribute__',
 '__hash__',
 '__init__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__self__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'im_class',
 'im_func',
 'im_self']
In [181]: dir(goodies.wppscaper)
Out[181]: 
['__call__',
 '__class__',
 '__cmp__',
 '__delattr__',
 '__doc__',
 '__format__',
 '__func__',
 '__get__',
 '__getattribute__',
 '__hash__',
 '__init__',
 '__new__',
 '__reduce__',
 '__reduce_ex__',
 '__repr__',
 '__self__',
 '__setattr__',
 '__sizeof__',
 '__str__',
 '__subclasshook__',
 'im_class',
 'im_func',
 'im_self']
So I simple cant understand why I dont have access to:

goodies.wpscaper.wpjfetch
goodies.wpscaper.wpsoup

or

goodies.wppscaper.wppjfetch
goodies.wppscaper.wppsoup

why cant I see them?? I am truly confused.

Last edited by metallica1973; 08-26-2015 at 02:43 PM.
 
Old 08-26-2015, 03:51 PM   #5
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
Well, my next guess would be they are private / protected to within the functions they are defined, ie. they are not global / public to the class?? (maybe)
 
1 members found this post helpful.
Old 08-26-2015, 08:53 PM   #6
metallica1973
Senior Member
 
Registered: Feb 2003
Location: Washington D.C
Posts: 2,190

Original Poster
Rep: Reputation: 60
I think you are exactly right. I just have to figure out how to unencapulate it or unhide it. Someone else brought this to my attention and said that I can return it inside the method which would break the encapulation. I am playing around with it to see what I come up with. But you hit it on the pinhead first so you get credit, simply what you said just didnt hit me until later.
 
Old 08-27-2015, 03:14 AM   #7
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,008

Rep: Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193Reputation: 3193
No probs ... glad we got there Maybe you can just define the variables outside the methods and then use / set them inside??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: Call super class virtual method from replacement method hydraMax Programming 4 05-01-2013 10:34 AM
[SOLVED] Python OOP - Class and code in seperate files, not working madsovenielsen Programming 1 08-25-2010 11:56 AM
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM
Question About Dlopen And Constructor Method George2 Programming 3 03-31-2006 08:54 PM
Class constructor not being called ChimpFace9000 Programming 1 06-03-2002 08:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration