国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

基于爬蟲框架scrapy的bili爬蟲

2023-03-17 16:15 作者:蕪湖小量化  | 我要投稿

# 蜘蛛程序
import scrapy
from scrapy import Selector
from ..items import GetItem ?# 導(dǎo)入

class BiliSpider(scrapy.Spider):
? ?name = 'bili'
? ?allowed_domains = ['bilibili.com']
? ?start_urls = ['https://www.bilibili.com/';] ? ?# 爬取的頁(yè)面

? ?def parse(self, response):
? ? ? ?sel = Selector(response)
? ? ? ?list_items = sel.xpath('/html/body/div[2]/div[2]/main/div[2]/div/div[1]/div')
? ? ? ?for list_item in list_items:
? ? ? ? ? ?spider_item = GetItem()
? ? ? ? ? ?spider_item['title'] = list_item.css('h3::attr(title)').extract() ?# 標(biāo)題
? ? ? ? ? ?spider_item['author'] = list_item.css('span.bili-video-card__info--author::text').extract() ?# 作者
? ? ? ? ? ?spider_item['time'] = list_item.css('span.bili-video-card__info--date::text').extract() ?# 時(shí)間
? ? ? ? ? ?spider_item['link'] = list_item.css('h3 > a::attr(href)').extract() ?# 鏈接
? ? ? ? ? ?yield spider_item

# items文件

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy


class GetItem(scrapy.Item):
? ?# define the fields for your item here like:
? ?# name = scrapy.Field()
? ?title = scrapy.Field()
? ?author = scrapy.Field()
? ?time = scrapy.Field()
? ?link = scrapy.Field()

# 配置

在setting文件中打開cookies,添加請(qǐng)求頭

# 命令行啟動(dòng),保存為csv文件

?scrapy crawl bili -o bili.csv

效果圖預(yù)覽


基于爬蟲框架scrapy的bili爬蟲的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
揭西县| 承德市| 海林市| 汕头市| 凌源市| 濮阳县| 漯河市| 兴义市| 巴彦县| 西宁市| 陕西省| 青神县| 电白县| 双桥区| 安福县| 大渡口区| 商丘市| 社旗县| 延安市| 定安县| 普安县| 万宁市| 桃园县| 吉安市| 岑溪市| 峨山| 大城县| 武邑县| 芷江| 依安县| 泰宁县| 漳州市| 南平市| 邯郸县| 本溪市| 扬中市| 延寿县| 南宁市| 从江县| 兰坪| 郎溪县|