Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not getting Info(Title)
#1
Im following a webscraping coure: https://www.linkedin.com/learning/web-sc...u=70295562

I am not getting the title out of this website: https://pythonscraping.com/linkedin/ietf.html

Wham am I doing wrong?
My code:
import scrapy


class BasicsSpider(scrapy.Spider):
name = 'ietf'
allowed_domains = ['pythonscraping.com']
start_urls = ['https://pythonscraping.com/linkedin/ietf.html']

def parse(self, response):

title = response.xpath('//span[@class="title"]/text()').get()


return{"title": title}

Output:

PS C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\WebS\ietf_project\ietf_project\spiders\ietf_scraper\ietf_scraper\spiders> scrapy runspider ietf.py
2023-01-24 13:54:34 [scrapy.utils.log] INFO: Scrapy 2.7.1 started (bot: ietf_scraper)
2023-01-24 13:54:34 [scrapy.utils.log] INFO: Versions: lxml 4.9.2.0, libxml2 2.9.12, cssselect 1.2.0, parsel 1.7.0, w3lib 2.1.1, Twisted 22.10.0, Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)], pyOpenSSL 23.0.0 (OpenSSL 3.0.7 1 Nov 2022), cryptography 39.0.0, Platform Windows-10-10.0.19044-SP0
2023-01-24 13:54:34 [scrapy.crawler] INFO: Overridden settings:
{'BOT_NAME': 'ietf_scraper',
'NEWSPIDER_MODULE': 'ietf_scraper.spiders',
'REQUEST_FINGERPRINTER_IMPLEMENTATION': '2.7',
'ROBOTSTXT_OBEY': True,
'SPIDER_LOADER_WARN_ONLY': True,
'SPIDER_MODULES': ['ietf_scraper.spiders'],
'TWISTED_REACTOR': 'twisted.internet.asyncioreactor.AsyncioSelectorReactor'}
2023-01-24 13:54:34 [asyncio] DEBUG: Using selector: SelectSelector
2023-01-24 13:54:34 [scrapy.utils.log] DEBUG: Using reactor: twisted.internet.asyncioreactor.AsyncioSelectorReactor
2023-01-24 13:54:34 [scrapy.utils.log] DEBUG: Using asyncio event loop: asyncio.windows_events._WindowsSelectorEventLoop
2023-01-24 13:54:34 [scrapy.extensions.telnet] INFO: Telnet Password: ef9e68c85363e3c9
2023-01-24 13:54:34 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
'scrapy.extensions.telnet.TelnetConsole',
'scrapy.extensions.logstats.LogStats']
2023-01-24 13:54:35 [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']
2023-01-24 13:54:35 [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']
2023-01-24 13:54:35 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2023-01-24 13:54:35 [scrapy.core.engine] INFO: Spider opened
2023-01-24 13:54:35 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2023-01-24 13:54:35 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2023-01-24 13:54:36 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://pythonscraping.com/robots.txt&gt; from <GET http://pythonscraping.com/robots.txt&gt;
2023-01-24 13:54:37 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://pythonscraping.com/robots.txt&gt; (referer: None)
2023-01-24 13:54:37 [scrapy.downloadermiddlewares.redirect] DEBUG: Redirecting (301) to <GET https://pythonscraping.com/&gt; from <GET http://pythonscraping.com/&gt;
2023-01-24 13:54:38 [scrapy.core.engine] DEBUG: Crawled (200) <GET https://pythonscraping.com/&gt; (referer: None)
2023-01-24 13:54:38 [scrapy.core.engine] INFO: Closing spider (finished)
2023-01-24 13:54:38 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 892,
'downloader/request_count': 4,
'downloader/request_method_count/GET': 4,
'downloader/response_bytes': 14088,
'downloader/response_count': 4,
'downloader/response_status_count/200': 2,
'downloader/response_status_count/301': 2,
'elapsed_time_seconds': 2.315037,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2023, 1, 24, 11, 54, 38, 117934),
'httpcompression/response_bytes': 68923,
'httpcompression/response_count': 1,
'log_count/DEBUG': 7,
'log_count/INFO': 10,
'response_received_count': 2,
'robotstxt/request_count': 1,
'robotstxt/response_count': 1,
'robotstxt/response_status_count/200': 1,
'scheduler/dequeued': 2,
'scheduler/dequeued/memory': 2,
'scheduler/enqueued': 2,
'scheduler/enqueued/memory': 2,
'start_time': datetime.datetime(2023, 1, 24, 11, 54, 35, 802897)}
2023-01-24 13:54:38 [scrapy.core.engine] INFO: Spider closed (finished)
PS C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\WebS\ietf_project\ietf_project\spiders\ietf_scraper\ietf_scraper\spiders>
Reply
#2
Use code tag
Use yield and not return and now you do not save the ouptut now,just get run info of scrapy.
import scrapy

class BasicsSpider(scrapy.Spider):
    name = 'ietf'
    allowed_domains = ['pythonscraping.com']
    start_urls = ['https://pythonscraping.com/linkedin/ietf.html']

    def parse(self, response):
        title = response.xpath('//span[@class="title"]/text()').get()
        yield {"title": title}
So if i run this as scrapy crawl ietf -o title.json
Then dos title.json has the title.
Output:
[ {"title": "A Standard for the Transmission of IP Datagrams on Avian Carriers"} ]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  <title> django page title dynamic and other field (not working) lemonred 1 1,383 Nov-04-2021, 08:50 PM
Last Post: lemonred

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020