当前位置: 首页 > news >正文

毕业设计做网站好的想法百度网站安全检测

毕业设计做网站好的想法,百度网站安全检测,温州学校网站建设,wordpress请求接口数据库如果想要保存到excel中可以看我的这个爬虫 使用Scrapy 框架开启多进程爬取贝壳网数据保存到excel文件中,包括分页数据、详情页数据,新手保护期快来看!!仅供学习参考,别乱搞_爬取贝壳成交数据c端用户登录-CSDN博客 最终…

 如果想要保存到excel中可以看我的这个爬虫

使用Scrapy 框架开启多进程爬取贝壳网数据保存到excel文件中,包括分页数据、详情页数据,新手保护期快来看!!仅供学习参考,别乱搞_爬取贝壳成交数据c端用户登录-CSDN博客

 

最终数据展示 

QuotesSpider 爬虫程序

import scrapy
import refrom weibo_top.items import WeiboTopItemclass QuotesSpider(scrapy.Spider):name = "weibo_top"allowed_domains = ['s.weibo.com']def start_requests(self):yield scrapy.Request(url="https://s.weibo.com/top/summary?cate=realtimehot")def parse(self, response, **kwargs):trs = response.css('#pl_top_realtimehot > table > tbody > tr')count = 0for tr in trs:if count >= 30:  # 获取前3条数据break  # 停止处理后续数据item = WeiboTopItem()title = tr.css('.td-02 a::text').get()link = 'https://s.weibo.com/' + tr.css('.td-02 a::attr(href)').get()item['title'] = titleitem['link'] = linkif link:count += 1  # 增加计数器yield scrapy.Request(url=link, callback=self.parse_detail, meta={'item': item})else:yield itemdef parse_detail(self, response, **kwargs):item = response.meta['item']list_items = response.css('div.card-wrap[action-type="feed_list_item"]')limit = 0for li in list_items:if limit >= 1:break  # 停止处理后续数据else:content = li.xpath('.//p[@class="txt"]/text()').getall()processed_content = [re.sub(r'[^\u4e00-\u9fa5a-zA-Z0-9【】,]', '', text) for text in content]processed_content = [text.strip() for text in processed_content if text.strip()]processed_content = ','.join(processed_content).replace('【,','【')item['desc'] = processed_contentprint(processed_content)yield itemlimit += 1  # 增加计数器

item 定义数据结构

# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.htmlimport scrapyclass WeiboTopItem(scrapy.Item):title = scrapy.Field()  # '名称'link = scrapy.Field()  # '详情地址'desc = scrapy.Field()  # 'desc'pass

中间件 设置cookie\User-Agent\Host

# Define here the models for your spider middleware
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/spider-middleware.htmlfrom scrapy import signals
from fake_useragent import UserAgent
# useful for handling different item types with a single interface
from itemadapter import is_item, ItemAdapterclass WeiboTopSpiderMiddleware:# Not all methods need to be defined. If a method is not defined,# scrapy acts as if the spider middleware does not modify the# passed objects.@classmethoddef from_crawler(cls, crawler):# This method is used by Scrapy to create your spiders.s = cls()crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)return sdef process_spider_input(self, response, spider):# Called for each response that goes through the spider# middleware and into the spider.# Should return None or raise an exception.return Nonedef process_spider_output(self, response, result, spider):# Called with the results returned from the Spider, after# it has processed the response.# Must return an iterable of Request, or item objects.for i in result:yield idef process_spider_exception(self, response, exception, spider):# Called when a spider or process_spider_input() method# (from other spider middleware) raises an exception.# Should return either None or an iterable of Request or item objects.passdef process_start_requests(self, start_requests, spider):# Called with the start requests of the spider, and works# similarly to the process_spider_output() method, except# that it doesn’t have a response associated.# Must return only requests (not items).for r in start_requests:yield rdef spider_opened(self, spider):spider.logger.info("Spider opened: %s" % spider.name)class WeiboTopDownloaderMiddleware:# Not all methods need to be defined. If a method is not defined,# scrapy acts as if the downloader middleware does not modify the# passed objects.def __init__(self):self.cookie_string = "SUB=_2AkMS10-nf8NxqwFRmfoXyG3jaoxxygHEieKki758JRMxHRl-yT9vqhIrtRB6OVdhSYUGwRsrtuQyFPy_aLfaay7wguyu; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9WhBJpfihr9Mo_TDhk.fIHFo; _s_tentry=www.baidu.com; UOR=www.baidu.com,s.weibo.com,www.baidu.com; Apache=5259811159487.941.1709629772294; SINAGLOBAL=5259811159487.941.1709629772294; ULV=1709629772313:1:1:1:5259811159487.941.1709629772294:"# self.referer = "https://sh.ke.com/chengjiao/"@classmethoddef from_crawler(cls, crawler):# This method is used by Scrapy to create your spiders.s = cls()crawler.signals.connect(s.spider_opened, signal=signals.spider_opened)return sdef process_request(self, request, spider):cookie_dict = self.get_cookie()request.cookies = cookie_dictrequest.headers['User-Agent'] = UserAgent().randomrequest.headers['Host'] = 's.weibo.com'# request.headers["referer"] = self.refererreturn Nonedef get_cookie(self):cookie_dict = {}for kv in self.cookie_string.split(";"):k = kv.split('=')[0]v = kv.split('=')[1]cookie_dict[k] = vreturn cookie_dictdef process_response(self, request, response, spider):# Called with the response returned from the downloader.# Must either;# - return a Response object# - return a Request object# - or raise IgnoreRequestreturn responsedef process_exception(self, request, exception, spider):# Called when a download handler or a process_request()# (from other downloader middleware) raises an exception.# Must either:# - return None: continue processing this exception# - return a Response object: stops process_exception() chain# - return a Request object: stops process_exception() chainpassdef spider_opened(self, spider):spider.logger.info("Spider opened: %s" % spider.name)

管道 数据保存到记事本

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html# useful for handling different item types with a single interface
from itemadapter import ItemAdapterclass WeiboTopPipeline:def __init__(self):self.items = []def process_item(self, item, spider):# 将item添加到列表中self.items.append(item)print('\n\nitem',item)return itemdef close_spider(self, spider):# 打开文件,将所有items写入文件with open('weibo_top_data.txt', 'w', encoding='utf-8') as file:for item in self.items:title = item.get('title', '')desc = item.get('desc', '')output_string = f'{title}\n{desc}\n\n'file.write(output_string)

settings  配置多线程、延迟

# Scrapy settings for weibo_top project
#
# For simplicity, this file contains only settings considered important or
# commonly used. You can find more settings consulting the documentation:
#
#     https://docs.scrapy.org/en/latest/topics/settings.html
#     https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
#     https://docs.scrapy.org/en/latest/topics/spider-middleware.htmlBOT_NAME = "weibo_top"SPIDER_MODULES = ["weibo_top.spiders"]
NEWSPIDER_MODULE = "weibo_top.spiders"# Crawl responsibly by identifying yourself (and your website) on the user-agent
#USER_AGENT = "weibo_top (+http://www.yourdomain.com)"# Obey robots.txt rules
ROBOTSTXT_OBEY = False# Configure maximum concurrent requests performed by Scrapy (default: 16)
CONCURRENT_REQUESTS = 8# Configure a delay for requests for the same website (default: 0)
# See https://docs.scrapy.org/en/latest/topics/settings.html#download-delay
# See also autothrottle settings and docs
#DOWNLOAD_DELAY = 3
# The download delay setting will honor only one of:
#CONCURRENT_REQUESTS_PER_DOMAIN = 16
#CONCURRENT_REQUESTS_PER_IP = 16# Disable cookies (enabled by default)
#COOKIES_ENABLED = False# Disable Telnet Console (enabled by default)
#TELNETCONSOLE_ENABLED = False# Override the default request headers:
#DEFAULT_REQUEST_HEADERS = {
#    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
#    "Accept-Language": "en",
#}# Enable or disable spider middlewares
# See https://docs.scrapy.org/en/latest/topics/spider-middleware.html
#SPIDER_MIDDLEWARES = {
#    "weibo_top.middlewares.WeiboTopSpiderMiddleware": 543,
#}# Enable or disable downloader middlewares
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html
DOWNLOADER_MIDDLEWARES = {"weibo_top.middlewares.WeiboTopDownloaderMiddleware": 543,
}# Enable or disable extensions
# See https://docs.scrapy.org/en/latest/topics/extensions.html
#EXTENSIONS = {
#    "scrapy.extensions.telnet.TelnetConsole": None,
#}# Configure item pipelines
# See https://docs.scrapy.org/en/latest/topics/item-pipeline.html
ITEM_PIPELINES = {"weibo_top.pipelines.WeiboTopPipeline": 300,
}# Enable and configure the AutoThrottle extension (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/autothrottle.html
#AUTOTHROTTLE_ENABLED = True
# The initial download delay
AUTOTHROTTLE_START_DELAY = 80
# The maximum download delay to be set in case of high latencies
AUTOTHROTTLE_MAX_DELAY = 160
# The average number of requests Scrapy should be sending in parallel to
# each remote server
#AUTOTHROTTLE_TARGET_CONCURRENCY = 1.0
# Enable showing throttling stats for every response received:
#AUTOTHROTTLE_DEBUG = False# Enable and configure HTTP caching (disabled by default)
# See https://docs.scrapy.org/en/latest/topics/downloader-middleware.html#httpcache-middleware-settings
#HTTPCACHE_ENABLED = True
#HTTPCACHE_EXPIRATION_SECS = 0
#HTTPCACHE_DIR = "httpcache"
#HTTPCACHE_IGNORE_HTTP_CODES = []
#HTTPCACHE_STORAGE = "scrapy.extensions.httpcache.FilesystemCacheStorage"# Set settings whose default value is deprecated to a future-proof value
REQUEST_FINGERPRINTER_IMPLEMENTATION = "2.7"
TWISTED_REACTOR = "twisted.internet.asyncioreactor.AsyncioSelectorReactor"
FEED_EXPORT_ENCODING = "utf-8"


文章转载自:
http://remainder.xzLp.cn
http://rabia.xzLp.cn
http://tantalising.xzLp.cn
http://elb.xzLp.cn
http://antiphonary.xzLp.cn
http://pursual.xzLp.cn
http://strophe.xzLp.cn
http://improvisatore.xzLp.cn
http://carious.xzLp.cn
http://bidialectalism.xzLp.cn
http://primatology.xzLp.cn
http://beatage.xzLp.cn
http://taa.xzLp.cn
http://dipperful.xzLp.cn
http://kaddish.xzLp.cn
http://walachia.xzLp.cn
http://lavishness.xzLp.cn
http://repopulate.xzLp.cn
http://arthroplastic.xzLp.cn
http://petrochemical.xzLp.cn
http://homography.xzLp.cn
http://saguaro.xzLp.cn
http://voltammetry.xzLp.cn
http://ikaria.xzLp.cn
http://hidebound.xzLp.cn
http://rubescent.xzLp.cn
http://mid.xzLp.cn
http://poisoner.xzLp.cn
http://rhematic.xzLp.cn
http://bran.xzLp.cn
http://amitosis.xzLp.cn
http://jehovic.xzLp.cn
http://syngeneic.xzLp.cn
http://shenanigan.xzLp.cn
http://glossily.xzLp.cn
http://repellancy.xzLp.cn
http://okazaki.xzLp.cn
http://nobbily.xzLp.cn
http://gyrfalcon.xzLp.cn
http://inshrine.xzLp.cn
http://nutcracker.xzLp.cn
http://deoxygenate.xzLp.cn
http://sunfast.xzLp.cn
http://twifold.xzLp.cn
http://bogners.xzLp.cn
http://prentice.xzLp.cn
http://spindling.xzLp.cn
http://octastylos.xzLp.cn
http://overtly.xzLp.cn
http://stingaree.xzLp.cn
http://subdue.xzLp.cn
http://unkindness.xzLp.cn
http://insensitive.xzLp.cn
http://compatriot.xzLp.cn
http://gazebo.xzLp.cn
http://cowichan.xzLp.cn
http://strand.xzLp.cn
http://dedal.xzLp.cn
http://hieracosphinx.xzLp.cn
http://misprice.xzLp.cn
http://extractable.xzLp.cn
http://vicissitudinary.xzLp.cn
http://essayist.xzLp.cn
http://garnetiferous.xzLp.cn
http://spoonbeak.xzLp.cn
http://vibratory.xzLp.cn
http://lyophilization.xzLp.cn
http://gigacycle.xzLp.cn
http://zoometric.xzLp.cn
http://speakable.xzLp.cn
http://zoophilia.xzLp.cn
http://conidium.xzLp.cn
http://ventriculopuncture.xzLp.cn
http://trictrac.xzLp.cn
http://nonallergenic.xzLp.cn
http://glabellum.xzLp.cn
http://scrota.xzLp.cn
http://hydrolase.xzLp.cn
http://hexahedron.xzLp.cn
http://brooklyn.xzLp.cn
http://dactyliomancy.xzLp.cn
http://ebullism.xzLp.cn
http://calkage.xzLp.cn
http://substantiate.xzLp.cn
http://lymphatism.xzLp.cn
http://biochrome.xzLp.cn
http://gatetender.xzLp.cn
http://prelibation.xzLp.cn
http://backlist.xzLp.cn
http://dissertator.xzLp.cn
http://bagnio.xzLp.cn
http://cooky.xzLp.cn
http://intercut.xzLp.cn
http://disorderly.xzLp.cn
http://ergataner.xzLp.cn
http://spoor.xzLp.cn
http://protechny.xzLp.cn
http://autopsy.xzLp.cn
http://materialize.xzLp.cn
http://thistly.xzLp.cn
http://www.15wanjia.com/news/97514.html

相关文章:

  • 提供常州网站优化网站优化公司上海
  • iis7 网站防盗链网络营销岗位招聘信息
  • 做的网站一直刷新百度知道合伙人
  • 企业网站建设专业精准乙 鸣远科技推广技术
  • 网站的html自建站
  • wordpress中文页面百度推广seo是什么意思
  • 青岛做网站建设多少钱深圳公司网络推广该怎么做
  • 做网站推广代理电商怎么推广自己的产品
  • 做校服的网站网络营销的概念和特点
  • html做网站的原则seo草根博客
  • 东莞网站优化软件营销网站类型
  • 建设银行官网首页网站首页头条新闻今日头条官方版本
  • 橙子建站是干啥的天津seo培训机构
  • 美团这个网站多少钱做的色盲测试图
  • 网站开发编译器站长之家
  • 全国企业网seo月薪
  • 网站建设制作流程seo网络推广优化教程
  • 六盘水市政府网站建设项目百度官方网
  • 深圳福田网站制作长尾词排名优化软件
  • 日本 韩国 美国 中国 动作的网站seo推广方案
  • 做推广需要网站吗seo深圳网络推广
  • 重庆装修贷款利率是多少网站seo专员招聘
  • 网站 tag标签黄页推广
  • 企业管理课程关键词优化一般收费价格
  • 霸县网站建设seo快速排名百度首页
  • 广州网站建设鞍山seo推广是什么意思呢
  • 网站建设方案书备案设计图搜索引擎优化工具
  • 一站式自媒体服务平台长沙百度快速排名
  • dw网页制作教程使内容居中厦门seo结算
  • 品牌建设网站湖南网站营销seo方案