Issue
I am struggling with the basic understanding of classes and esp. inherited classes (if that is a right term). My child class is supposed to use functions from the parent but super() seems to init the parent class while I want to use their functions directly instead.
What I plan to do: My program will be a web scraper. It is supposed to scrape different webpages which always returns the same data structure. Such use case could be: Product title will be searched in multiple markets. Amazon.com, Ebay.com, craiglist.com and Aliexpress while each of the pages will give me their cheapest price.
The parent is the selenium class handling the browser, scraping, exceptions etc. Now for each market I would implement a separate file/class that manages the specific xpath etc to find and pass the command to the parent class to execute.
This would give me for example following file/class structure:
- Selenium
- amazon_com
- ebay_com
- craiglist_com
- aliexpress_cn
However each of the sub classes/files like would need the functions of the selenium class.
initially I had one long list of functions within the selenium class. However due an ever growing number of markets to check and constantly changing class names etc. I would much prefer to separate it in several files (potentially ending up in the ball park of 50 sub classes...).
Since I even struggle to explain my problem I believe I have overlooked a very simple solution or missed a design concept entirely. Can someone point me to some good reading source I could use to learn and crack that nut?
Solution
To call the function foo
on a parent class, you can do super().foo()
Answered By - do-no-van
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.