私はちょうど傷病の治療を始めました。ログインが必要なウェブサイトをクロールしようとしています。私はgithubのためにうまく働いています。私はフォームIDを見つけ、必要なフィールドを追加し、すべてが計画どおりに進んだ。詐欺のログイン認証が機能していない
しかし、私はinvestopediaのウェブサイトで同じことを試みたとき、私は騒がしくなった。私はコードを添付しています。私はformnumber = 0を追加しようとしている
class Investo_spider(InitSpider):
name = 'investo_spider'
allowed_domains = ['investopedia.com']
login_page = 'http://www.investopedia.com/accounts/login.aspx'
start_urls = ['http://www.investopedia.com']
def init_request(self):
return Request(url=self.login_page, callback=self.login)
def login(self, response):
return FormRequest.from_response(response,
formdata={'email': 'mymail','password': 'mypass'},
callback=self.check_login_response)
def check_login_response(self, response):
if "myname" in response.body:
self.log("Successfully logged in. Let's start crawling!")
self.initialized()
else:
self.log("Login was unsuccessful")
def parse_item(self, response):
print 'I got in here, finally!!!!'
pass
、clickdata = { 'NR':0}デフォルトは既に正しいフォームとクリッカブルを選択したもののおよび方法変更(POSTまたはGETを)。
驚いたことに、私は同じパラメータを使用して機械化ブラウザで作業しました。私はhtmlをHtmlResponseオブジェクトに変換して、その処理が処理できるようにします。
br = mechanize.Browser()
br.open("http://www.investopedia.com/accounts/login.aspx")
br.select_form(nr=0)
br.form["email"] = 'mymail'
br.form["password"] = 'mypass'
br.submit()
br.open('http://www.investopedia.com')
response = HtmlResponse(url="some_url"),body=br.response().read())
しかし、これは私が解決策の最善ではないと仮定しており、周りのMechanizeのブラウザを運ぶために必要がありますを意味します。私は何かが欠けているかもしれないと思う。私は本当にこれにあなたの入力を感謝します。ありがとう!
私はこれまでに実行したことがありますが、私はセレンを使用してログインを行い、クッキーを保存し、それらを使用するようにしました。 'init_request'で返すのではなく、リクエストを' yield 'しようとしてください。 –
'{' remember ':' 1 '}' – kev
@RafaelAlmeidaセレンのサンプルコードがありますか? @kev '{'remember': '1'}'追加の送信は効果がありませんでした。私は機械化オプションのために行くことを考えていますが、あまりエレガントではありません。 – user3225486