我需要一些帮助。我的刮刀现在正在运行,它会创建items.csv文件,但只将product_name等放入其中....我该如何解决这个问题? 这是我的代码:
import scrapy
import csv
class ProductSetSpider(scrapy.Spider):
name = "Product_spider"
start_urls = ['https://www.grainger.com/category/bacharach/ecatalog/N-1z125ev']
FEED_URI= r"C:\Users\Owner\Desktop\scraperProject\ScraperProject\items.csv"
# custom_settings = {'FEED_EXPORT_FIELDS': ["product_name" , ],
# }
def parse(self, response):
self.log('I just visited' + response.url)
yield {
'product_name': response.css('h2.list-view__product-heading::text').extract()
#'product_detail' : response.css('').extract_first()
#'product_rating' : response.css('').extract_first()
#'product_category' : response.css('').extract_first()
#'product_company' : response.css('').extract_first()
}
Output_file = open('items.csv', 'w') #items.csv is name of output file
fieldnames = ['product_name', 'product_details', 'product_rating', 'product_category', 'product_company'] #adding header to file
writer = csv.DictWriter(Output_file, fieldnames=fieldnames)
writer.writeheader()
for url in start_urls:
writer.writerow({product_name: response.url(fieldnames, css)}) #writing data into file.
file_name.close()
答案 0 :(得分:1)
在您的蜘蛛集的settings.py或custom_settings属性中
var infowindow = new google.maps.InfoWindow({
content:"<input type='button' id='clickableItem'value='consulter profile'>"
});
google.maps.event.addListener(infowindow, 'domready', () => {
//now my elements are ready for dom manipulation
var clickableItem = document.getElementById('clickableItem');
clickableItem.addEventListener('click', () => {
this.navCtrl.push(HomePage);
});
});
marker.addListener('click', event => {
infowindow.open(this.map, marker);
});