このウェブサイトを破棄したいと思います: Meetic.fr、meetic.com のフランス語版。
目標は、認証後に接続されている人数 (ページの上部に表示) を知ることです。
ここにスパイダーがあります:([kobeddl、stack123456]は、何かを試したい場合の実際のログインです)
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.http import FormRequest, Request
from meetic.items import MeeticItem
class MeeticSpider(BaseSpider):
name = "meetic"
allowed_domains = ["meetic.fr"]
start_urls = ["http://www.meetic.fr/"]
def parse(self, response):
print 'TEST1'
return [FormRequest.from_response(response, formdata={'log': 'kobeddl', 'pwd': 'stack123456'}, callback=self.after_login)]
def after_login(self, response):
# check login succeed before going on
if "authentication failed" in response.body:
self.log("Login failed", level=log.ERROR)
print 'TEST2'
return
# We've successfully authenticated, let's have some fun!
else:
print 'TEST3'
return Request(url="http://www.meetic.fr/scheduler.php?url=", callback=self.parse_tastypage)
def parse_tastypage(self, response):
hxs = HtmlXPathSelector(response)
item = MeeticItem()
item['nb'] = hxs.select('/html/body/div/div/div/div/div/div/ul/li[2]/a/div/span').extract()
print 'TEST4'
return item
コマンド プロンプトの結果は次のとおりです。
編集 :ご覧のとおり、最初の print ステートメントだけ
TEST1
が機能しています。私はpythonとscrapyが初めてなので、理由はおそらくばかげています。
ここで私のスパイダーに間違いがあると思います:if "authentication failed" in response.body:
他のスパイダーでそれを見つけましたが、このスパイダーに調整する方法がわかりません。
設定ファイルのユーザーエージェントも変更しました
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.7'
前もって感謝します