1. 程式人生 > >scrapy 試用 爬取百度首頁

scrapy 試用 爬取百度首頁

# -*- coding: utf-8 -*-
import scrapy


class BaiduSpider(scrapy.Spider):
    name = 'baidu'
    allowed_domains = ['baidu.com']
    start_urls = ['http://baidu.com/']

    def parse(self, response):
       # print('結果返回')
        print(response)
        print(type(response))
      #  print('結果結束')
        
html = str(response.body,encoding="utf8") with open("baidu.html","w",encoding="utf8")as f: f.write(html)