Scrapy 爬取了 0 页 0 项

问题描述 投票:0回答:1

我使用 scrapy 创建了一个爬虫,从 Indeed 上抓取数据,希望将职位、公司、地点、描述、资格返回到 csv 文件中。但我遇到了问题:它没有返回任何结果,我不知道问题出在哪里。我是 scrapy 和网络抓取的新手。

我的蜘蛛代码

import scrapy
from scrapy.crawler import CrawlerProcess

class JobSpider(scrapy.Spider):
  name = 'Job'

  def start_requests(self):
    start_urls = 'https://vn.indeed.com/q-data-engineer-intern-vi%E1%BB%87c-l%C3%A0m.html'
    headers = { 
        'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'
        }
    yield scrapy.Request(url = start_urls, headers = headers, callback = self.parse)

  def parse(self, response):
    job_detail = response.css('h2.jobTitle > a.jcs-JobTitle::attr(href)').extract()
    for link in job_detail:
      yield response.follow(url = link, callback = self.parse2)

  def parse2(self, response):

    items = dict()

    job_title = response.css('h1.jobsearch-JobInfoHeader-title > span::text').extract_first()
    company = response.css('div[data-testid="inlineHeader-companyName"] > a::text').extract_first()
    location = response.css('div[data-testid="jobsearch-JobInfoHeader-companyLocation"] > span::text').extract_first()
    job_description = response.css('div#jobDescriptionText > p::text').extract_first()
    qualification = response.css('div#jobDescriptionText > div:nth-child(6) > div::text').extract_first()
    pluses = response.css('div#jobDescriptionText > div:nth-child(10) > div::text').extract_first()
    items['title'] = job_title
    items['company'] = company
    items['location'] = location
    items['description'] = job_description
    items['qualification'] = qualification
    items['pluses'] = pluses

    yield items


process = CrawlerProcess(settings={'FEEDS': {'dataJob.csv':{'format':'csv'}}})
process.crawl(JobSpider)
process.start()

我的日志文件

INFO:scrapy.utils.log:Scrapy 2.11.0 started (bot: scrapybot)
2024-01-24 00:41:17 [scrapy.utils.log] INFO: Scrapy 2.11.0 started (bot: scrapybot)
INFO:scrapy.utils.log:Versions: lxml 4.9.4.0, libxml2 2.10.3, cssselect 1.2.0, parsel 1.8.1, w3lib 2.1.2, Twisted 22.10.0, Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0], pyOpenSSL 23.3.0 (OpenSSL 3.1.4 24 Oct 2023), cryptography 41.0.7, Platform Linux-6.1.58+-x86_64-with-glibc2.35
2024-01-24 00:41:17 [scrapy.utils.log] INFO: Versions: lxml 4.9.4.0, libxml2 2.10.3, cssselect 1.2.0, parsel 1.8.1, w3lib 2.1.2, Twisted 22.10.0, Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0], pyOpenSSL 23.3.0 (OpenSSL 3.1.4 24 Oct 2023), cryptography 41.0.7, Platform Linux-6.1.58+-x86_64-with-glibc2.35
INFO:scrapy.addons:Enabled addons:
[]
2024-01-24 00:41:17 [scrapy.addons] INFO: Enabled addons:
[]
/usr/local/lib/python3.10/dist-packages/scrapy/utils/request.py:254: ScrapyDeprecationWarning: '2.6' is a deprecated value for the 'REQUEST_FINGERPRINTER_IMPLEMENTATION' setting.

It is also the default value. In other words, it is normal to get this warning if you have not defined a value for the 'REQUEST_FINGERPRINTER_IMPLEMENTATION' setting. This is so for backward compatibility reasons, but it will change in a future version of Scrapy.

See the documentation of the 'REQUEST_FINGERPRINTER_IMPLEMENTATION' setting for information on how to handle this deprecation.
  return cls(crawler)
DEBUG:scrapy.utils.log:Using reactor: twisted.internet.epollreactor.EPollReactor
2024-01-24 00:41:17 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.epollreactor.EPollReactor
INFO:scrapy.extensions.telnet:Telnet Password: 6d140ec38f893d8a
2024-01-24 00:41:17 [scrapy.extensions.telnet] INFO: Telnet Password: 6d140ec38f893d8a
INFO:scrapy.middleware:Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.feedexport.FeedExporter',
 'scrapy.extensions.logstats.LogStats']
2024-01-24 00:41:17 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.feedexport.FeedExporter',
 'scrapy.extensions.logstats.LogStats']
INFO:scrapy.crawler:Overridden settings:
{}
2024-01-24 00:41:17 [scrapy.crawler] INFO: Overridden settings:
{}
INFO:scrapy.middleware:Enabled downloader middlewares:
['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']
2024-01-24 00:41:17 [scrapy.middleware] INFO: Enabled downloader middlewares:
['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']
INFO:scrapy.middleware:Enabled spider middlewares:
['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware',
 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware',
 'scrapy.spidermiddlewares.referer.RefererMiddleware',
 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware',
 'scrapy.spidermiddlewares.depth.DepthMiddleware']
2024-01-24 00:41:17 [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']
INFO:scrapy.middleware:Enabled item pipelines:
[]
2024-01-24 00:41:17 [scrapy.middleware] INFO: Enabled item pipelines:
[]
INFO:scrapy.core.engine:Spider opened
2024-01-24 00:41:17 [scrapy.core.engine] INFO: Spider opened
INFO:scrapy.extensions.logstats:Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2024-01-24 00:41:17 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
INFO:scrapy.extensions.telnet:Telnet console listening on 127.0.0.1:6023
2024-01-24 00:41:17 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): publicsuffix.org:443
2024-01-24 00:41:17 [urllib3.connectionpool] DEBUG: Starting new HTTPS connection (1): publicsuffix.org:443
DEBUG:urllib3.connectionpool:https://publicsuffix.org:443 "GET /list/public_suffix_list.dat HTTP/1.1" 200 83770
2024-01-24 00:41:17 [urllib3.connectionpool] DEBUG: https://publicsuffix.org:443 "GET /list/public_suffix_list.dat HTTP/1.1" 200 83770
DEBUG:scrapy.core.engine:Crawled (403) <GET https://vn.indeed.com/q-data-engineer-intern-vi%E1%BB%87c-l%C3%A0m.html> (referer: None)
2024-01-24 00:41:17 [scrapy.core.engine] DEBUG: Crawled (403) <GET https://vn.indeed.com/q-data-engineer-intern-vi%E1%BB%87c-l%C3%A0m.html> (referer: None)
INFO:scrapy.spidermiddlewares.httperror:Ignoring response <403 https://vn.indeed.com/q-data-engineer-intern-vi%E1%BB%87c-l%C3%A0m.html>: HTTP status code is not handled or not allowed
2024-01-24 00:41:18 [scrapy.spidermiddlewares.httperror] INFO: Ignoring response <403 https://vn.indeed.com/q-data-engineer-intern-vi%E1%BB%87c-l%C3%A0m.html>: HTTP status code is not handled or not allowed
INFO:scrapy.core.engine:Closing spider (finished)
2024-01-24 00:41:18 [scrapy.core.engine] INFO: Closing spider (finished)
INFO:scrapy.extensions.feedexport:Stored csv feed (0 items) in: dataJob.csv
2024-01-24 00:41:18 [scrapy.extensions.feedexport] INFO: Stored csv feed (0 items) in: dataJob.csv
INFO:scrapy.statscollectors:Dumping Scrapy stats:
{'downloader/request_bytes': 333,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 7899,
 'downloader/response_count': 1,
 'downloader/response_status_count/403': 1,
 'elapsed_time_seconds': 0.382056,
 'feedexport/success_count/FileFeedStorage': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2024, 1, 24, 0, 41, 18, 48488, tzinfo=datetime.timezone.utc),
 'httpcompression/response_bytes': 12643,
 'httpcompression/response_count': 1,
 'httperror/response_ignored_count': 1,
 'httperror/response_ignored_status_count/403': 1,
 'log_count/DEBUG': 4,
 'log_count/INFO': 12,
 'memusage/max': 139415552,
 'memusage/startup': 139415552,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2024, 1, 24, 0, 41, 17, 666432, tzinfo=datetime.timezone.utc)}
2024-01-24 00:41:18 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 333,
 'downloader/request_count': 1,
 'downloader/request_method_count/GET': 1,
 'downloader/response_bytes': 7899,
 'downloader/response_count': 1,
 'downloader/response_status_count/403': 1,
 'elapsed_time_seconds': 0.382056,
 'feedexport/success_count/FileFeedStorage': 1,
 'finish_reason': 'finished',
 'finish_time': datetime.datetime(2024, 1, 24, 0, 41, 18, 48488, tzinfo=datetime.timezone.utc),
 'httpcompression/response_bytes': 12643,
 'httpcompression/response_count': 1,
 'httperror/response_ignored_count': 1,
 'httperror/response_ignored_status_count/403': 1,
 'log_count/DEBUG': 4,
 'log_count/INFO': 12,
 'memusage/max': 139415552,
 'memusage/startup': 139415552,
 'response_received_count': 1,
 'scheduler/dequeued': 1,
 'scheduler/dequeued/memory': 1,
 'scheduler/enqueued': 1,
 'scheduler/enqueued/memory': 1,
 'start_time': datetime.datetime(2024, 1, 24, 0, 41, 17, 666432, tzinfo=datetime.timezone.utc)}
INFO:scrapy.core.engine:Spider closed (finished)
2024-01-24 00:41:18 [scrapy.core.engine] INFO: Spider closed (finished)

我使用与网络 books.toscrape.com 相同的框架,并且运行正常。有人可以帮我解释一下这个错误吗

感谢您的帮助

我在 vscode 和 ggcolab 上运行了代码,但它返回了相同的结果

python web-scraping scrapy web-crawler
1个回答
0
投票

首先,如果你查看 DevTools,那么如果我没记错的话,你的 url 后面应该跟着一个 post 请求。其次,网站上有cloudflare,它是一个非常流行的系统,用于保护网站免受DDoS攻击和解析。尝试访问curlconverter 网站并将您请求的网址粘贴到那里。如果有帮助,那么作为一个选项,从浏览器获取 cookie 并在 Scrapy 中使用它们。

© www.soinside.com 2019 - 2024. All rights reserved.