python - Scrapy - Load a yaml file with a relative path inside the spider -


I am trying to implement my scrapy crawlers , but the problem is that my Pass yaml file is that I am trying to load from inside the , it works when the spider is loaded from the shell: scrapy crawl & lt; spider-name & gt; . But when the spider is deployed under scrapyd , the path of the yaml file should be complete .

The relative path for code> has been posted on on scrapyd :

  scrapyd-deploy default -p & Lt; project-name & gt; Curl http://127.0.0.1:6800/schedule.json -d project = & lt; Project-name & gt; -D spider = & lt; Spider-name & gt;   

and the yaml file is loaded as:

  open ('../categories.yaml', 'r') F: Pass    

The

relative path is relative to the current working directory (the directory that started with your script). If you want to load a file from a path relative to the current script location, then you can try the following:

  root_dir = os.path.abspath (os.path.dirname (__ file__) ) yaml_pass = OS path.join (root_dir, '../categories/categories.yaml') with open (yaml_path, 'r') f: pass    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -