I am trying to populate start_url with SELECT from MYSQL table using spider.py . When I run "scrapy runpider spider.py", I do not get the output, it just finished without errors.
I checked the SELECT query in a python script, and start_url populated the records from the MYSQL table.
spider.py
from scrapy.spider import BaseSpider from scrapy.selector import Selector import MySQLdb class ProductsSpider(BaseSpider): name = "Products" allowed_domains = ["test.com"] start_urls = [] def parse(self, response): print self.start_urls def populate_start_urls(self, url): conn = MySQLdb.connect( user='user', passwd='password', db='scrapy', host='localhost', charset="utf8", use_unicode=True ) cursor = conn.cursor() cursor.execute( 'SELECT url FROM links;' ) rows = cursor.fetchall() for row in rows: start_urls.append(row[0]) conn.close()
maryo source share