2016-11-29 5 views
-1

私はOOPを開始しようとしており、この方法でスクリプトを書き直すことに決めました。 Webページは、私が保存したいリンクの箱を持っているので、私は次のコードに私のクラスのBs4からメソッドを継承する

class webpage(BeautifulSoup): 

    def __init__(self, link, html, links): 

     self.link = link 
     driver = webdriver.PhantomJS() 
     driver.get(link) 
     self.html = driver.page_source 
     self.links = [] 

    def forty_pages(self): 

     soup = BeautifulSoup(html, 'html.parser') 
     link_box = soup.find('div', {'id': 'sliderBottom'}) 
     rest = link_box.find_all('a') 
     forty_links = [] 

     for i in rest: 
      try: 
       link = i.get('href') 
       forty_links.append(link) 
      except: 
       pass 
     self.links.append(x for x in forty_links) 

test = webpage(link=root) 
test.forty_pages() 

を行う問題は、それは私がするときself.htmlが自分自身を埋める必要があり、約混乱しています

TypeError: module.__init__() takes at most 2 arguments (3 given) 

を言うということですドライバはhtmlデータを含む文字列を返します。誰もこれに光を当てることができますか? 編集:私は、組成物の必要がないことを告げていますが、私はクラスの中からモジュールBS4を呼び出すことはできませんので、私は、例えば...これをimplrment方へと立ち往生しています:

class rightmove_page(object): 

    def __init__(self, link): 
     self.link = link 

    def forty_pages(self): 
     driver = webdriver.PhantomJS() 
     html = driver.get(self.link) 
     soup = BeautifulSoup(html, 'html.parser') 
     print(soup) 

ができますエラー:

Traceback (most recent call last): 
    File "/home/sn/Documents/Projects/House_Prices/class_pased.py", line 21, in <module> 
    test.forty_pages() 
    File "/home/sn/Documents/Projects/House_Prices/class_pased.py", line 17, in forty_pages 
    soup = BeautifulSoup(html, 'html.parser') 
TypeError: 'module' object is not callable 
+1

あなたはこれらの他のパラメータはどこから来ると思いますか?彼らなしでそれを直接呼びます。 – jonrsharpe

+0

なぜBeautifulSoupをここにサブクラス化したいですか?それをする理由はないようです。継承された機能を使用していません。 –

+0

私はBeautifulSoups関数のいくつかを間違いなく使用したいと思っています。構図を読み、特定のBs4メソッドを読み込むだけです。 – entercaspa

答えて

0

申し訳ありません皆さんは、その行われ、それを整理は、単にクラスメソッドでBS4を紹介する代わりに、デフのinitクラスの一部の関数を含めるしようとしています。あなたは正しいですダニエルローズマン感謝の男

関連する問題