2017-05-25 21 views
0

私は、Web廃棄に関する新しいことを試しています。私はウェブサイトにログインしようとしているし、特定のアイテムをこすります。Python Scrapy:ウェブサイトにログインしてからスクラップします

私はこの目的のためにこのコードを構築しましたが、動作しません。私は、次のコードを設定している、ログインするscrapy.FormRequestを使用して、と私は、これまでのドキュメントから読み取るものを使用しています:

class HomelyspiderSpider(scrapy.Spider): 
    name = "homelyspider" 
    allowed_domains = ["homely.com.au"] 
    start_urls = ['https://homely.com.au/'] 

    def parse(self, response): 

      yield scrapy.FormRequest.from_response(
       response, 
       formxpath='.//div[@class="Modal-body"]/form', 
       formdata={ 
        'usernameOrEmail': 'myusername',    
        'password': 'mypassword', 
       }, 
       clickdata = { "type": "Submit" }, 
       callback=self.after_login 
      ) 
    def after_login(self, response): 
      "DO SCRAPING NOW" 

ログインページのHTML

<div class="Auth Auth--modal"> 
    <div class="signin "> 
     <div class="Modal-header"> 
      <h1 class="Modal-title">Sign in</h1> 
     </div> 
     <div class="Modal-body"> 
      <p class="subtitle">Instant sign in with Facebook or Google:</p><a class="Button Button--icon Button--facebook small-12" href="/authentication/redirect/Facebook"><span role="presentation" class="icon-wrapper"><svg class="icon icon-facebook"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-facebook"></use></svg></span><span class="label">Continue with Facebook</span></a><a class="Button Button--icon Button--google small-12" href="/authentication/redirect/Google"><span role="presentation" class="icon-wrapper"><svg class="icon icon-google"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-google"></use></svg></span><span class="label">Continue with Google</span></a> 
      <p>or using your email:</p> 
      <form> 
       <label class=""> 
        <input type="text" aria-label="Email or Username" required="" pattern="^[^-\s].+" title="Please enter a valid value" name="usernameOrEmail" placeholder="Email or Username" class="FormControl" value=""> 
       </label> 
       <label class=""> 
        <input type="password" aria-label="Password" required="" pattern="^[^-\s].+" title="Please enter a valid value" name="password" placeholder="Password" class="FormControl"> 
       </label> 
       <button class="Button Button--alt small-12" type="submit"><span class="Button-message">Sign In</span> 
       </button> 
      </form> 
      <p class="forgotten"> 
       <button class="ButtonLink">Forgot Password?</button> 
      </p> 
     </div> 
     <div class="Modal-line"></div> 
     <div class="Modal-footer"> 
      <p> 
       <!-- react-text: 71 -->Not yet a member? 
       <!-- /react-text --> 
       <button class="ButtonLink">Register with Homely</button> 
      </p> 
     </div> 
    </div> 
</div> 

を、私は、これは関係ありません知っていますfromはページにありますが、依然として私はリンクと提供されたステップと要素を示しています。

この私がでログインをクリックする必要がメインページさ:

enter image description here

enter image description here

それから私のフォームのコードが含まれているポップアップサインインしています以前に提供した:

enter image description here

私はここで間違っていますか? scrapy DOCsから私が理解していることから、私の治療様式要求コードは正しく機能するでしょうか?

答えて

0

とValueError:> それがフォームを見つけられませんが見つかりません要素...

+0

私はあまりにもそれを見ることができます..あなたは、なぜ言うことができますか?フォームxpathはOKです –

+0

xpathを使用しているときにエラーが発生して以来実際にはありません。 – minime

+0

なぜサインインボタンをクリックするまでフォームが表示されないのですか? –

関連する問題