I've installed scrapy and created a spider that works when run from the command line with the command scrapy crawl getBUCPower. My issue is that I need to run the spider from another script when something specific happens. I have a separate python script thats just a test for now, but it tries to run the spider by the line:
execfile("../scrapy/data_spider/data_spider/spiders/getBUCPower.py")
When I run that script, I immediately get the error:
File "getBUCPower.py", line 2, in
import scrapy
ImportError: No module named scrapy
I have scrapy installed correctly as it work when I run the scrapy crawl command so I am unaware of what the issue is right now.
Here is my spider
import scrapy
from scrapy.crawler import CrawlerProcess
from scrapy import Spider
from scrapy.loader import ItemLoader
class DataSpider(Spider):
#sets the name of the spider
name = 'getBUCPower'
#sets the pipeline the spider should use
custom_settings = {
'ITEM_PIPELINES': {
'data_spider.pipelines.CsvPipeline': 300
}
}
#sets the url the spider should crawl
allowed_domains = [ip]
start_urls = [ipHTTP]
def parse(self, response):
#sets the information the sipder should grab
BUCPower = response.xpath('//*[@id="mmwpaTxPower"]/text()').extract_first()
#returns the information
yield{"BUCPower" : BUCPower}
process = CrawlerProcess(settings={
'FEED_FORMAT': 'json',
'FEED_URI': 'items.json'
})
process.crawl(DataSpider)
process.start()
I currently have scrapy 1.6 and am using Python 2.7.16
The expected result is to run the spider from another script, but instead it has an issue importing scrapy.