Я пытаюсь получить содержимое этого URL: https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion=
Но похоже, что ответ не содержит тела. Хотя в голове есть сценарий. Это то, что я пробовал (добавил заголовки из браузера, где эта страница нормально загружается).
import scrapy
class TestSpider(scrapy.Spider):
name = 'testspider'
headers = {
"Host": "www.alljobs.co.il",
"Sec-Fetch-Site": "same-origin",
"Sec-Fetch-Mode": "navigate",
"Referer": "https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion=",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9,ne;q=0.8,it;q=0.7,mt;q=0.6",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36"
}
def start_requests(self):
url = 'https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion='
yield scrapy.Request(url=url, callback=self.parse, headers=self.headers)
def parse(self, response):
print(response.status, 'open-board' in response.body)
Вывод:
2020-02-10 09:18:56 [scrapy.utils.log] INFO: Scrapy 1.8.0 started (bot: scrapybot)
2020-02-10 09:18:56 [scrapy.utils.log] INFO: Versions: lxml 4.5.0.0, libxml2 2.9.10, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.10.0, Python 2.7.15+ (default, Jul 9 2019, 16:51:35) - [GCC 7.4.0], pyOpenSSL 19.1.0 (OpenSSL 1.1.1d 10 Sep 2019), cryptography 2.8, Platform Linux-4.15.0-20-generic-x86_64-with-LinuxMint-19-tara
2020-02-10 09:18:56 [scrapy.crawler] INFO: Overridden settings: {'SPIDER_LOADER_WARN_ONLY': True}
2020-02-10 09:18:56 [scrapy.extensions.telnet] INFO: Telnet Password: eec1d23ac0e5b987
2020-02-10 09:18:56 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.memusage.MemoryUsage',
'scrapy.extensions.logstats.LogStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.corestats.CoreStats']
2020-02-10 09:18:56 [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']
2020-02-10 09:18:56 [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']
2020-02-10 09:18:56 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2020-02-10 09:18:56 [scrapy.core.engine] INFO: Spider opened
2020-02-10 09:18:56 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2020-02-10 09:18:56 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2020-02-10 09:18:57 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion=> (referer: https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion=)
(200, False)
2020-02-10 09:18:57 [scrapy.core.engine] INFO: Closing spider (finished)
2020-02-10 09:18:57 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 515,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 34340,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'elapsed_time_seconds': 1.32754,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2020, 2, 10, 3, 33, 57, 430553),
'log_count/DEBUG': 1,
'log_count/INFO': 10,
'memusage/max': 53485568,
'memusage/startup': 53485568,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2020, 2, 10, 3, 33, 56, 103013)}
2020-02-10 09:18:57 [scrapy.core.engine] INFO: Spider closed (finished)
С Selenium, похоже, тоже та же проблема.
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'/path_to_/chromedriver')
url = "https://www.alljobs.co.il/SearchResultsGuest.aspx?page=1&position=&type=&freetxt=&city=®ion="
driver.get(url)
html = driver.page_source
print("works= {}".format("open-board" in html))
Отображается works= False
. Я не уверен, почему это не работает.
Любая помощь будет принята с благодарностью. Спасибо!