我正在尝试用Scrapy抓取一个购物网站上的所有评论。我发现了这个密码:
import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
class deneme(CrawlSpider):
name = 'deneme'
allowed_domains = ['hepsiburada.com']
start_urls = ['https://www.hepsiburada.com/']
rules = (
Rule(LinkExtractor(), callback='parse_item', follow=True),
)
def parse_item(self, response):
filename = response.url.split("/")[-2] + '.html'
with open(filename, 'wb') as f:
f.write(response.body)
这个代码会爬网所有的网站。但我只想抓取网站上的评论,并将其写入MongoDB数据库。我不擅长Python。我该怎么做?谢谢您!在
代码如下:
刮痧;输出.txt在
相关问题 更多 >
编程相关推荐