0
StackOverflow.com'u taramak ve atmak için Scrapy kullanıyorum. Bu so.pyScrapy'nin sonucu belirli bir JSON biçimine nasıl dışa aktarılır?
import scrapy
class StackOverflowSpider(scrapy.Spider):
name = 'stackoverflow'
start_urls = ['http://stackoverflow.com']
def parse(self, response):
for href in response.css('.question-summary h3 a::attr(href)'):
full_url = response.urljoin(href.extract())
yield scrapy.Request(full_url, callback=self.parse_question)
def parse_question(self, response):
yield {
'link': response.url,
}
Beklenen sonuç: so.json(geçerli JSON biçimi)
[
"http://stackoverflow.com/questions/36421917/exponential-number-in-custom-number-format-of-excel",
"http://stackoverflow.com/questions/36421343/can-not-install-requirements-txt",
"http://stackoverflow.com/questions/36418815/difference-between-two-approaches-to-pass-parameters-to-web-server",
"http://stackoverflow.com/questions/36421743/sharing-an-oracle-database-connection-between-simultaneous-celery-tasks",
"http://stackoverflow.com/questions/36421941/jquery-add-css-style",
]
Sonra çalıştırın:
scrapy runspider so.py -o so.json
sonucu değil beklendiği gibi. Buraya sıkıştım.
Bu sonuç, sonra yukarıdaki komutu çalıştırın: https://gist.github.com/donhuvy/7f75e0cf30ab0fe2ba79069ffa328b31 Hala beklenen sonuca benzemiyor. –
Cevabı düzelttim, bir kez daha kontrol et. –
Gözden geçirilmiş cevabınızı uyguladıktan sonra komut çalıştırıyorum, sonuçta https://gist.github.com/donhuvy/cc21a2a99b64fa367dbaec70f27b564c. Sonuç beklenmiyor. Sorunu çözmeme yardım et! –