当我运行此代码块时,它成功运行,但name
字段返回空结果。请帮助我检查,我错过了什么?
这是我的密码
import scrapy
class TruckspiderSpider(scrapy.Spider):
name = 'truckspider'
allowed_domains = ['www.quicktransportsolutions.com']
start_urls = ['https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php']
def parse(self, response):
containers = response.css('div.col-md-4')
for container in containers:
yield
{
'name': container.css('a::text').get(),
}
这是我得到的结果
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.scraper] DEBUG: Scraped from <200 https://www.quicktransportsolutions.com/carrier/usa-trucking-companies.php>
{'name': None}
2023-02-01 19:17:42 [scrapy.core.engine] INFO: Closing spider (finished)
2023-02-01 19:17:42 [scrapy.extensions.feedexport] INFO: Stored json feed (55 items) in: truck.json
2023-02-01 19:17:42 [scrapy.statscollectors] INFO: Dumping Scrapy stats:
{'downloader/request_bytes': 265,
'downloader/request_count': 1,
'downloader/request_method_count/GET': 1,
'downloader/response_bytes': 4912,
'downloader/response_count': 1,
'downloader/response_status_count/200': 1,
'elapsed_time_seconds': 1.916927,
'feedexport/success_count/FileFeedStorage': 1,
'finish_reason': 'finished',
'finish_time': datetime.datetime(2023, 2, 1, 18, 17, 42, 902380),
'httpcompression/response_bytes': 22809,
'httpcompression/response_count': 1,
'item_scraped_count': 55,
'log_count/DEBUG': 57,
'log_count/INFO': 11,
'log_count/WARNING': 1,
'response_received_count': 1,
'scheduler/dequeued': 1,
'scheduler/dequeued/memory': 1,
'scheduler/enqueued': 1,
'scheduler/enqueued/memory': 1,
'start_time': datetime.datetime(2023, 2, 1, 18, 17, 40, 985453)}
2023-02-01 19:17:42 [scrapy.core.engine] INFO: Spider closed (finished)
2条答案
按热度按时间elcex8rz1#
您得到的结果集为空,因为CSS选择器
div.col-md-4
的方式不正确,而是使用[class="col-md-4 column"]
并获取所需的输出。输出:
运行下面的代码而不使用scrapy项目
bjg7j2ky2#
@Md. Fazlul Hoque感谢您的时间和回复。
我终于找到了解决办法。我让我的本地计算机访问这个文件:
2023-02-02 10:54:17 [filelock] DEBUG: Attempting to acquire lock 2733195998640 on C:\Users\ChiNedu\AppData\Local\Programs\Python\Python310\lib\site-packages\tldextract\.suffix_cache/publicsuffix.org-tlds\de84b5ca2167d4c83e38fb162f2e8738.tldextract.json.lock
在我的AppData文件夹里,它像魔法一样工作。太高兴了。