Я пытаюсь сканировать сайт, используя скрап. Веб-сайт содержит логин форума, и я не могу войти через scrapy.
import scrapy
from scrapy.http import FormRequest
class ExtractUrls(scrapy.Spider):
# This name must be unique always
name = "geninfofetch"
def start_requests(self):
urls = ['http://generatortechnicalforum.org/portal/login.php','http://www.generatortechnicalforum.org/portal/forum/viewforum.php?forum_id=117&fgroup=1&src=rss' ]
for url in urls:
yield FormRequest(url = url, formdata = {'user_name': '*******', 'user_pass': '**********'}, callback = self.parse)
# Parse function
def parse(self, response):
# Extra feature to get title
title = response.css('title::text').extract()
# Get anchor tags
links = response.css('a::attr(href)').extract()
for item in zip(title, links):
scrapped_info = {
"title" : item[0],
"link" : item[1]
}
yield scrapped_info
Я хочу войти в систему и извлечь данные с этой страницы, и для целей тестирования я попытался извлечь заголовок, а также информацию о ссылке, но в результате кажется, что страница не вошла в систему.
Вывод вышеуказанного кода (CSV-файл):
title | link
IGTC Forum - Login | /
Вход:
2019-05-09 13:55:41 [scrapy.utils.log]
INFO: Scrapy 1.5.2 started (bot: igtc) 2019-05-09 13:55:41 [scrapy.utils.log]
INFO: Versions: lxml 4.1.1.0, libxml2 2.9.7, cssselect 1.0.3, parsel 1.5.1, w3lib
1.20.0, Twisted 19.2.0, Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)], pyOpenSSL 17.5.0 (OpenSSL
1.1.1b 26 Feb 2019), cryptography 2.6.1, Platform Windows-10-10.0.17134-SP0 2019-05-09 13:55:41 [scrapy.crawler]
INFO: Overridden settings: {'BOT_NAME': 'igtc', 'FEED_FORMAT': 'csv', 'FEED_URI': 'ab.csv', 'NEWSPIDER_MODULE': 'igtc.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['igtc.spiders']} 2019-05-09 13:55:41 [scrapy.extensions.telnet]
INFO: Telnet Password: 373666e24f6193ee 2019-05-09 13:55:41 [scrapy.middleware]
INFO: Enabled extensions: ['scrapy.extensions.corestats.CoreStats', 'scrapy.extensions.telnet.TelnetConsole', 'scrapy.extensions.feedexport.FeedExporter', 'scrapy.extensions.logstats.LogStats'] 2019-05-09 13:55:42 [scrapy.middleware]
INFO: Enabled downloader middlewares: ['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware', 'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware', 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware', 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware', 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware', 'scrapy.downloadermiddlewares.retry.RetryMiddleware', 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware', 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware', 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware', 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware', 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware', 'scrapy.downloadermiddlewares.stats.DownloaderStats'] 2019-05-09 13:55:42 [scrapy.middleware]
INFO: Enabled spider middlewares: ['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware', 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware', 'scrapy.spidermiddlewares.referer.RefererMiddleware', 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware', 'scrapy.spidermiddlewares.depth.DepthMiddleware'] 2019-05-09 13:55:42 [scrapy.middleware]
INFO: Enabled item pipelines: [] 2019-05-09 13:55:42 [scrapy.core.engine]
INFO: Spider opened 2019-05-09 13:55:42 [scrapy.extensions.logstats]
INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 2019-05-09 13:55:42 [scrapy.extensions.telnet]
DEBUG: Telnet console listening on
127.0.0.1:6023 2019-05-09 13:55:43 [scrapy.downloadermiddlewares.redirect]
DEBUG: Redirecting (301) to <GET https://www.generatortechnicalforum.org/robots.txt> from <GET http://www.generatortechnicalforum.org/robots.txt> 2019-05-09 13:55:43 [scrapy.downloadermiddlewares.redirect]
DEBUG: Redirecting (301) to <GET https://generatortechnicalforum.org/robots.txt> from <GET http://generatortechnicalforum.org/robots.txt> 2019-05-09 13:55:45 [scrapy.core.engine]
DEBUG: Crawled (200) <GET https://www.generatortechnicalforum.org/robots.txt> (referer: None) 2019-05-09 13:55:45 [scrapy.core.engine]
DEBUG: Crawled (200) <GET https://generatortechnicalforum.org/robots.txt> (referer: None) 2019-05-09 13:55:46 [scrapy.downloadermiddlewares.redirect]
DEBUG: Redirecting (301) to <POST https://www.generatortechnicalforum.org/portal/forum/viewforum.php?forum_id=117&fgroup=1&src=rss> from <POST http://www.generatortechnicalforum.org/portal/forum/viewforum.php?forum_id=117&fgroup=1&src=rss> 2019-05-09 13:55:46 [scrapy.downloadermiddlewares.redirect]
DEBUG: Redirecting (301) to <POST https://generatortechnicalforum.org/portal/login.php> from <POST http://generatortechnicalforum.org/portal/login.php> 2019-05-09 13:55:46 [scrapy.downloadermiddlewares.redirect]
DEBUG: Redirecting (302) to <GET https://www.generatortechnicalforum.org/portal/login.php?req=%2Fportal%2Fforum%2Fviewforum.php%3Fforum_id%3D117%26amp%3Bfgroup%3D1%26amp%3Bsrc%3Drss> from <POST https://www.generatortechnicalforum.org/portal/forum/viewforum.php?forum_id=117&fgroup=1&src=rss> 2019-05-09 13:55:46 [scrapy.core.engine]
DEBUG: Crawled (200) <POST https://generatortechnicalforum.org/portal/login.php> (referer: None) 2019-05-09 13:55:46 [scrapy.core.scraper]
DEBUG: Scraped from <200 https://generatortechnicalforum.org/portal/login.php> {'title': 'IGTC Forum - Login', 'link': '/'} 2019-05-09 13:55:47 [scrapy.core.engine]
DEBUG: Crawled (200) <GET https://www.generatortechnicalforum.org/portal/login.php?req=%2Fportal%2Fforum%2Fviewforum.php%3Fforum_id%3D117%26amp%3Bfgroup%3D1%26amp%3Bsrc%3Drss> (referer: None) 2019-05-09 13:55:47 [scrapy.core.scraper]
DEBUG: Scraped from <200 https://www.generatortechnicalforum.org/portal/login.php?req=%2Fportal%2Fforum%2Fviewforum.php%3Fforum_id%3D117%26amp%3Bfgroup%3D1%26amp%3Bsrc%3Drss> {'title': 'IGTC Forum - Login', 'link': '/'} 2019-05-09 13:55:47 [scrapy.core.engine]
INFO: Closing spider (finished) 2019-05-09 13:55:47 [scrapy.extensions.feedexport]
INFO: Stored csv feed (2 items) in: ab.csv 2019-05-09 13:55:47 [scrapy.statscollectors]
INFO: Dumping Scrapy stats: {'downloader/request_bytes': 2738, 'downloader/request_count': 9, 'downloader/request_method_count/GET': 5, 'downloader/request_method_count/POST': 4, 'downloader/response_bytes': 13537, 'downloader/response_count': 9, 'downloader/response_status_count/200': 4, 'downloader/response_status_count/301': 4, 'downloader/response_status_count/302': 1, 'finish_reason': 'finished', 'finish_time': datetime.datetime(2019, 5, 9, 8, 25, 47, 592036), 'item_scraped_count': 2, 'log_count/DEBUG': 12, 'log_count/INFO': 9, 'response_received_count': 4, 'scheduler/dequeued': 5, 'scheduler/dequeued/memory': 5, 'scheduler/enqueued': 5, 'scheduler/enqueued/memory': 5, 'start_time': datetime.datetime(2019, 5, 9, 8, 25, 42, 597326)} 2019-05-09 13:55:47 [scrapy.core.engine]
INFO: Spider closed (finished)