<jupyter_start><jupyter_text>*ถ้า error ให้ restart แล้ว run ใหม่*<jupyter_code>import scrapy
from scrapy.crawler import CrawlerProcess

# point Scrapy to Pantip.com
class PantipSpider(scrapy.Spider):
    name = "pantip_spider"
    start_urls = ['https://pantip.com/#trend']
    
    def parse(self, response):
        SET_SELECTOR = '.post-pick-nothumb'
        for topic in response.css(SET_SELECTOR):
            
            NAME_SELECTOR = 'a .post-pick-title ::text'
            DESC_SELECTOR = 'a .post-pick-desc ::text'
            BY_SELECTOR = 'div span ::text'
            
            yield {
                'title': topic.css(NAME_SELECTOR).extract_first(),
                'desc': topic.css(DESC_SELECTOR).extract_first(),
                'by': topic.css(BY_SELECTOR).extract_first(),
            }

# run Scrapy
process = CrawlerProcess()
process.crawl(PantipSpider)
process.start() # the script will block here until the crawling is finished<jupyter_output>2017-12-26 14:46:53 [scrapy.utils.log] INFO: Scrapy 1.4.0 started (bot: scrapybot)
2017-12-26 14:46:53 [scrapy.utils.log] INFO: Overridden settings: {}
2017-12-26 14:46:53 [scrapy.middleware] INFO: Enabled extensions:
['scrapy.extensions.corestats.CoreStats',
 'scrapy.extensions.telnet.TelnetConsole',
 'scrapy.extensions.memusage.MemoryUsage',
 'scrapy.extensions.logstats.LogStats']
2017-12-26 14:46:53 [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.[...]
{'fraction_non_alphanumeric': 0.12026275896917635, 'fraction_numerical': 0.029813036887316825, 'mean_word_length': 4.2105263157894735, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '355639', 'license': 'MIT', 'n_tokens_mistral': 703, 'n_tokens_neox': 646, 'n_words': 106, 'path': '3 Mining Pantip.com.ipynb', 'repo_name': 'Kanbc/mining-the-social-web', 'size': '1979'}