python Scrapy automation [关闭]

qzlgjiam  于 2024-01-05  发布在  Python
关注(0)|答案(2)|浏览(330)

已关闭。此问题需要更多focused。目前不接受回答。
**要改进此问题吗?**更新此问题,使其仅针对editing this post的一个问题。

昨天就关门了。
Improve this question
我是一名初级数据科学家,正在从事一个项目
在我抓取了几个网站后,他们让我自动化抓取过程
我使用scrapy作为这个问题的框架,并使用mongoDB来存储数据。
我做了我的研究,我发现scrapyd和气流可以让你这样做。
我从气流开始,但我发现它相当复杂的气流dags检测我的scrapy项目。根据您的专业知识,什么是最好的方式来自动化scrapy尽可能简单。
谢谢你的帮助

jw5wzhpr

jw5wzhpr1#

也许你可以使用Crawlab,点击here!我在工作中使用过5. 0版本,我认为它很好。

hkmswyz6

hkmswyz62#

你可以试试Scrapyd
使用mongo的示例代码结构

  1. import scrapy
  2. from scrapy.crawler import CrawlerProcess
  3. from pymongo import MongoClient
  4. class MySpider(scrapy.Spider):
  5. name = 'myspider'
  6. start_urls = ['https://your-url']
  7. def parse(self, response):
  8. # Extract data using Scrapy's selectors or regular expressions
  9. title = response.css('title::text').get()
  10. content = response.xpath('//p/text()').getall()
  11. # Connect to MongoDB
  12. client = MongoClient('localhost', 27017)
  13. db = client['mydatabase']
  14. collection = db['mycollection']
  15. collection.insert_one({'title': title, 'content': content})
  16. # spider locally
  17. process = CrawlerProcess()
  18. process.crawl(MySpider)
  19. process.start()
  20. # Scrapyd deployment:
  21. # scrapyd-deploy <target-project> -p myspider

字符串

展开查看全部

相关问题