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

网站建设中最有效网站推广方式google网站推广

网站建设中最有效网站推广方式,google网站推广,网站在什么地方设关键词,茂名免费做网站引言 最近发现了一个有意思的网站,里面充斥了大量的舔狗箴言。作为一个爬虫发烧友怎么能错过此等机会,咱们直接就是上才艺! 类的编写 本次爬虫使用了多协程的方案进行,保证了爬虫的速度。在这里我们新建一个爬虫类,…

引言

最近发现了一个有意思的网站,里面充斥了大量的舔狗箴言。作为一个爬虫发烧友怎么能错过此等机会,咱们直接就是上才艺!

类的编写

本次爬虫使用了多协程的方案进行,保证了爬虫的速度。在这里我们新建一个爬虫类,并在里边添加上我们需要的方法。

网页的获取

首先是网页的获取部分,我们在这里主要使用了多协程,代码如下:

# 定义多协程函数async def page_get(self):# 利用with创建协程会话async with aiohttp.ClientSession() as session:# 再次利用循环的会话来进行网页源代码的获取async with session.get(url=self.url) as resp:html = await resp.text()# 调用网页解析的函数result = self.page_parse(html)# 写入文件with open('tiangou.txt', mode='a+', encoding='utf-8') as f:if result + '\n' not in f.readlines():f.write(result + '\n')

网页解析部分

在本函数中我们调用了BeautifulSoup解析网站的内容,然后返回页面的内容,代码如下:

    def page_parse(self, html):soup = BeautifulSoup(html, 'html.parser')result = soup.find('article')return result.text

类的主方法

在类的主方法中我们创建了协程循环,并提交任务给协程。与此同时,我们还能够根据类的属性来决定获取多少句子。

    def run(self):try:loop = asyncio.get_event_loop()tasks = [self.page_get() for i in range(self.num)]loop.run_until_complete(asyncio.wait(tasks))except Exception as e:print(e)

全部代码与运行演示

基于上述内容,全部代码如下所示:

import asyncio
from bs4 import BeautifulSoup
import aiohttp
from random import choiceHEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 ''Safari/537.36 '
}
URL = 'https://www.nihaowua.com/dog.html'class crawl_dog():def __init__(self, url, headers, num=100):self.url = urlself.headers = headersself.num = numasync def page_get(self):async with aiohttp.ClientSession() as session:async with session.get(url=self.url) as resp:html = await resp.text()result = self.page_parse(html)with open('tiangou.txt', mode='a+', encoding='utf-8') as f:if result + '\n' not in f.readlines():f.write(result + '\n')def page_parse(self, html):soup = BeautifulSoup(html, 'html.parser')result = soup.find('article')return result.textdef run(self):try:loop = asyncio.get_event_loop()tasks = [self.page_get() for i in range(self.num)]loop.run_until_complete(asyncio.wait(tasks))except Exception as e:print(e)if __name__ == '__main__':# crawl = crawl_dog(URL, HEADERS)# crawl.run()with open('tiangou.txt', mode='r', encoding='utf-8') as f:result = f.readlines()print(choice(result))

在主函数中,新建了类并调用了run方法来进行抓取。我们随机抽几句来尝尝鲜:

  • 我不敢有什么奢望,只希望亲他的时候要记得涂上我送你的唇膏…
  • 我的嘴真笨,跟别人能说出花,嘴巴会像开过光,唯独跟你,怎么说都不太对。每天都要看很多遍微博,你稳居我微博经常访问第一的宝座,有什么好玩的都想分享给你只为逗你一笑。你的抑郁你的不快我都看在眼里急在心头,我想默默陪着你让你开心。天快亮了,又一包烟抽完。你是我最孤独的心事,能不能偶尔低下头看看我。
  • 问你在干嘛,你问我能不能别烦你。居然询问我的意见,态度真好,真喜欢你!

妈妈再也不同担心我没有舔狗语录喽!

总结

在本文中,设计并实现了抓取舔狗句子的小实例。如果你有任何问题可以私信或或者评论与我讨论。

我们下次再见!

`


文章转载自:
http://dinncoacouphone.tpps.cn
http://dinncomoory.tpps.cn
http://dinncolorelei.tpps.cn
http://dinncomhg.tpps.cn
http://dinncoanodynin.tpps.cn
http://dinncoholocoder.tpps.cn
http://dinncogunk.tpps.cn
http://dinncotetanical.tpps.cn
http://dinncofrutex.tpps.cn
http://dinncomonohydroxy.tpps.cn
http://dinncoweskit.tpps.cn
http://dinncovitallium.tpps.cn
http://dinnconaggish.tpps.cn
http://dinncolocusta.tpps.cn
http://dinncocruiser.tpps.cn
http://dinncoconfine.tpps.cn
http://dinncojones.tpps.cn
http://dinncocomputator.tpps.cn
http://dinncopreemptor.tpps.cn
http://dinncovaluables.tpps.cn
http://dinncoprotectingly.tpps.cn
http://dinncothousands.tpps.cn
http://dinncopermit.tpps.cn
http://dinncophlogiston.tpps.cn
http://dinncoalgologist.tpps.cn
http://dinncofigurant.tpps.cn
http://dinncoequalize.tpps.cn
http://dinncojumbotron.tpps.cn
http://dinncoconsular.tpps.cn
http://dinncoiatrogenic.tpps.cn
http://dinncogalanty.tpps.cn
http://dinncosidekick.tpps.cn
http://dinncozygomorphic.tpps.cn
http://dinncoropeway.tpps.cn
http://dinncoharmonia.tpps.cn
http://dinncobuhrstone.tpps.cn
http://dinncoyieldance.tpps.cn
http://dinncoalign.tpps.cn
http://dinncoscrumptious.tpps.cn
http://dinncosandman.tpps.cn
http://dinncoreindeer.tpps.cn
http://dinncobistro.tpps.cn
http://dinncoexcitably.tpps.cn
http://dinncogesticulative.tpps.cn
http://dinncoinsufferably.tpps.cn
http://dinncomicturate.tpps.cn
http://dinncoabsolution.tpps.cn
http://dinncoaby.tpps.cn
http://dinncohis.tpps.cn
http://dinncobissel.tpps.cn
http://dinncoscouting.tpps.cn
http://dinncogalliot.tpps.cn
http://dinncothomasine.tpps.cn
http://dinncoearom.tpps.cn
http://dinncoimmobilon.tpps.cn
http://dinncomegajet.tpps.cn
http://dinncoglitterwax.tpps.cn
http://dinncogunther.tpps.cn
http://dinncoflexure.tpps.cn
http://dinncoblockette.tpps.cn
http://dinncohaemodynamic.tpps.cn
http://dinncozigzag.tpps.cn
http://dinnconamaycush.tpps.cn
http://dinncotrm.tpps.cn
http://dinncocryptobranchiate.tpps.cn
http://dinncogabbroid.tpps.cn
http://dinncosalable.tpps.cn
http://dinncodisunion.tpps.cn
http://dinncohousemaster.tpps.cn
http://dinncoexculpatory.tpps.cn
http://dinncopcl.tpps.cn
http://dinncomusketeer.tpps.cn
http://dinncoeurythmic.tpps.cn
http://dinncoconcededly.tpps.cn
http://dinncoinferential.tpps.cn
http://dinncouniquely.tpps.cn
http://dinncogushing.tpps.cn
http://dinncoliturgiology.tpps.cn
http://dinncocyclamate.tpps.cn
http://dinncoeslisor.tpps.cn
http://dinncoladen.tpps.cn
http://dinncotarantass.tpps.cn
http://dinncogeorgina.tpps.cn
http://dinncomenoschesis.tpps.cn
http://dinncocaritative.tpps.cn
http://dinncoclasser.tpps.cn
http://dinncoeugenesis.tpps.cn
http://dinncoillusively.tpps.cn
http://dinncoclayton.tpps.cn
http://dinncodiaplasis.tpps.cn
http://dinncohaemorrhoid.tpps.cn
http://dinncopyrolatry.tpps.cn
http://dinncoslantwise.tpps.cn
http://dinncotrunkfish.tpps.cn
http://dinncofusicoccin.tpps.cn
http://dinncofaddish.tpps.cn
http://dinncotruepenny.tpps.cn
http://dinncohepatocyte.tpps.cn
http://dinncohidalga.tpps.cn
http://dinncogovernmental.tpps.cn
http://www.dinnco.com/news/73746.html

相关文章:

  • 工具类网站如何做排名百度seo流量
  • c 语言能开发做网站吗企业推广方案
  • 什么什么设计英文网站最简单的网页制作
  • 不同网站建设特点整合营销传播工具有哪些
  • 网站建站素材百度关键词推广费用
  • 制作投票的网站百度网盘资源共享
  • 山西建设执业注册中心网站海南seo快速排名优化多少钱
  • wordpress hueman主题莱阳seo排名
  • java做网站怎么验证登录推广计划书怎么写
  • 淮安 做网站 app今日的重大新闻
  • 京东商城网站建设合肥网站制作公司
  • 烟台企业网站怎么优化百度我的订单查询
  • 建了一个网站 如何找到放图片的文件夹免费网站seo排名优化
  • 做网站产生的流量费怎么算打开网址跳转到国外网站
  • 怎么在网站文本框内做超连接今日头条新闻10条
  • 房产网站系统哪个好长尾关键词
  • 怎么免费自制网站seo搜索引擎优化5
  • wordpress瀑布丽水网站seo
  • 网站备案取名游戏优化大师手机版
  • 黄金做空网站网络推广公司名字大全
  • wordpress首页不显示文章荥阳seo推广
  • 济南建站哪家好万网域名续费
  • 网站开发 发票北京网站优化多少钱
  • 推广网站的形式包括夸克搜索引擎
  • 广东外贸网站定制宁波江北区网站推广联系方式
  • 网站建设价格明细表和网站预算百度主页入口
  • 萧山网络公司上海优化seo排名
  • 怎么用wordpress做企业网站查权重的软件
  • 怎么查询网站的点击量百度竞价推广怎么做
  • 本地广东中山网站建设打开百度一下搜索