スクレイピーのログイン画面への対応でログインできない。
スクレイピーのマニュアル通りアナコンダプロンプトから進めてログイン対応するためのコードを書きました
ログインしたいURL:atbb.athome.jp
reins.pyというスパイダーを作成しました
書いたコード(reins.py)
import scrapy
from scrapy.linkextractors import LinkExtractor
from scrapy.spiders import CrawlSpider, Rule
from scrapy import FormRequest
#------------
class ReinsSpider(CrawlSpider):
name = 'reins'
allowed_domains = ['atbb.athome.jp']
start_urls = ['http://atbb.athome.jp']
#start_urlsからuser_uuid、
def parse(self,response):
user_uuid = response.xpath('//*[@id="user_uuid"]/@value').get()
#scrapyではformrequestクラスを使ってアイパスを入力する
yield FormRequest.form_response(
response,
formxpath = '//div[@class="loginForm"]',
formdata = {
"user_uuid":user_uuid,
"loginId":"AAAAA",
"password":"BBBBB"
},
callback = self.after_login()
)
#ログイン後Xpathにログアウトの文字が入っていれば成功、なければ失敗
def after_login(self,response):
if response.xpath('//li[@class="c-util__menu__logout"]/button/text()').get():
print("login succeeded!")
else:
print("login failed!")
すると何回もトライして失敗しているような結果が出ます。
Retrying <GET http://atbb.athome.jp> (failed 1 times): [<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.>]
2022-08-03 23:07:37 [scrapy.downloadermiddlewares.retry] DEBUG: Retrying <GET http://atbb.athome.jp> (failed 2 times): [<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.>]
2022-08-03 23:07:41 [scrapy.downloadermiddlewares.retry] ERROR: Gave up retrying <GET http://atbb.athome.jp> (failed 3 times): [<twisted.python.failure.Failure twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion.>]
'log_count/DEBUG': 4,
'log_count/ERROR': 4,
'log_count/INFO': 10,
'retry/count': 4,
'retry/max_reached': 2,
これは何が原因で、どうすれば解決するのでしょうか誰かご教授下さい、どうぞよろしくお願い致します。
0 likes