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

创办网站需要多少钱seo经典案例

创办网站需要多少钱,seo经典案例,如何发布自己做的网页,wordpress调用分类和文章一、准备过程 首先打开hao123漫画筛选区,网址是https://www.hao123.com/manhua/list/?finish&audience&area&cate&order1 在这里可以通过审查模式看到第一页的详细信息,而目的则是通过爬取漫画筛选页面的每部漫画的人气与题材来分析最近…

一、准备过程

首先打开hao123漫画筛选区,网址是https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1

在这里可以通过审查模式看到第一页的详细信息,而目的则是通过爬取漫画筛选页面的每部漫画的人气与题材来分析最近漫画迷的观漫需求

环境如下:

  python3.6.2    PyCharm

  Windows8.1  第三方库(jieba,wordcloud,bs4,Requests,re,wordcloud)

二、代码

1.用requests库和BeautifulSoup库,爬取hao123漫画网当前页面的每部漫画的漫画名、地域、题材、人气、链接等,将获取漫画详情的代码定义成一个函数 

def getCartoonDetail(cartoonUrl):

# 将获取hao123漫画详情的代码定义成一个函数 def getCartoonDetail(cartoonUrl):
def getCartoonDetail(cartoonUrl):resd = requests.get(cartoonUrl)resd.encoding = 'utf-8'soupd = BeautifulSoup(resd.text, 'html.parser')cartoons = {}# 获取除了标题外的字符串a = soupd.select('.title-wrap')[0].select('span')[0].text# 计算字符串的长度num = len(a)# 标题cartoons['title'] = soupd.select('.title-wrap')[0].text[:-num]ul = soupd.select('.info-list')[0]# 地域cartoons['territory'] = ul.select('li')[1].text.lstrip('地域:').replace('\xa0'," ")#漫画题材cartoons['theme'] = ul.select('li')[-2].text.lstrip('题材:').replace('\xa0'," ")#人气cartoons['moods'] = ul.select('li')[-1].text.lstrip('人气:')writeCartoonDetail(cartoons['theme'] + ' ' + cartoons['moods'] + '\n')return cartoons

2.取出一个漫画列表页的全部漫画 包装成函数def getListPage(pageUrl):

def getListPage(pageUrl):res = requests.get(pageUrl)res.encoding = 'utf-8'soup = BeautifulSoup(res.text, 'html.parser')cartoonlist = []for cartoon in soup.select('.item-1'):# cartoon.select('.title')获取列表里的漫画标题if len(cartoon.select('.title')) > 0:a = cartoon.select('a')[0].attrs['href']#链接cartoonlist.append(getCartoonDetail(a))return cartoonlist

3.获取总的漫画篇数,算出漫画总页数包装成函数def getPageN():

def getPageN():res = requests.get('https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1')res.encoding = 'utf-8'soup = BeautifulSoup(res.text, 'html.parser')n = int(soup.select('.gray')[1].text.lstrip('').rsplit('')[0])return n

4. 获取全部漫画列表页的全部漫画详情。爬取页面前30页,原因是爬取的数据太多,搞到电脑蓝屏,列表好像出现过溢出

cartoontotal = []
pageUrl = 'https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1'
cartoontotal.extend(getListPage(pageUrl))n = getPageN()
for i in range(2, 30 + 1):pageUrl = 'https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1&pn={}'.format(i)cartoontotal.extend(getListPage(pageUrl))

5.将爬取到所有信息通过pandas根据评分排序,然后只爬取'title'和'moods'两列的信息,并保存至excel表中

df = pandas.DataFrame(cartoontotal)
# 将爬取到所有信息通过pandas根据人气排序,然后只爬取'title''moods'两列的信息,并保存至excel表中
dfs=df.sort_index(by='moods', ascending=False)
dfsn=dfs[['title', 'moods']]
dfsn.to_excel('cartoon.xlsx', encoding='utf-8')

6.将爬取到的漫画题材通过构造方法writeNewsDetail(content)写入到文本cartoon.txt中

def writeCartoonDetail(content):f=open('cartoon.txt','a',encoding='utf-8')f.write(content)f.close()

 

三、生成词云

 通过导入wordcloud的包,来生成词云

from PIL import Image,ImageSequence
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud,ImageColorGenerator
# image= Image.open('./logo.jpg')
# graph = np.array(image)
# 获取上面保存的字典
title_dict = changeTitleToDict()
graph = np.array(title_dict)
font = r'C:\Windows\Fonts\simhei.ttf'
# backgroud_Image代表自定义显示图片,这里我使用默认的
backgroud_Image = plt.imread("G:/大三2/大数据/filedocuments/logo1.jpg")
wc = WordCloud(background_color='white',max_words=500,font_path=font, mask=backgroud_Image)
# wc = WordCloud(background_color='white',max_words=500,font_path=font)
wc.generate_from_frequencies(title_dict)
plt.imshow(wc)
plt.axis("off")
plt.show()

选择的图片:

 

原图:

由于生成的词云是按照背景色来生成的,故显示效果为

 

 一个矩形,明显不是我想要的效果,所以重新抠图如下:

 效果如下:

 四、遇到的问题及解决方案

 

1.在导入wordcloud这个包的时候,会遇到很多问题

首先通过使用pip install wordcloud这个方法在全局进行包的下载,可是最后会报错误error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: http://landinghub.visualstudio.com/visual-cpp-build-tools 

这需要我们去下载VS2017中的工具包,但是网上说文件较大,所以放弃。

之后尝试去https://www.lfd.uci.edu/~gohlke/pythonlibs/#wordcloud下载whl文件,然后安装。

下载对应的python版本进行安装,如我的就下载wordcloud-1.4.1-cp36-cp36m-win32.whl,wordcloud-1.4.1-cp36-cp36m-win_amd64

两个文件都放到项目目录中,两种文件都尝试安装

通过cd到这个文件的目录中,通过pip install wordcloud-1.4.1-cp36-cp36m-win_amd64,进行导入

但是两个尝试后只有win32的能导入,64位的不支持,所以最后只能将下好的wordcloud放到项目lib中,在Pycharm中import wordcloud,最后成功

2.在爬取漫画信息的时候,爬取漫画标题的时候,会因为soupd.select('.title-wrap')[0].text获取除标题外的其他值,如已完结,如下图

 

解决方案如下:

    # 获取除了标题外的字符串a = soupd.select('.title-wrap')[0].select('span')[0].text# 计算字符串的长度num = len(a)# 标题cartoons['title'] = soupd.select('.title-wrap')[0].text[:-num]

五、数据分析与结论

通过对词云的查看,可以看出漫画迷对于类型类型为搞笑、爱情、生活、魔幻、治愈、冒险等题材的漫画喜欢,而对都市、竞技、悬疑等题材的漫画选择很少,这说明观看漫画选择的大多数是有关于有趣与刺激的,而对于推理类的漫画选择少,这样在出版漫画时可以通过受众程度来出版。

而在这次作业中,我了解并实现如何爬取一个网站的有用信息,如何对爬取的信息分析并得到结论,虽然我对于大数据技术深度的技术并不了解,而且基础的知识也需要我不断加深巩固。

六、所有代码

# 大数据大作业
# 爬取hao123漫画网中的漫画人气最多的题材
import requests
import re
from bs4 import BeautifulSoup
import pandas
import jieba# 将爬取到的漫画题材通过构造方法writeNewsDetail(content)写入到文本cartoon.txt中
def writeCartoonDetail(content):f=open('cartoon.txt','a',encoding='utf-8')f.write(content)f.close()# 将获取hao123漫画详情的代码定义成一个函数 def getCartoonDetail(cartoonUrl):
def getCartoonDetail(cartoonUrl):resd = requests.get(cartoonUrl)resd.encoding = 'utf-8'soupd = BeautifulSoup(resd.text, 'html.parser')# print(cartoonUrl)cartoons = {}# 获取除了标题外的字符串a = soupd.select('.title-wrap')[0].select('span')[0].text# print(a)# 计算字符串的长度num = len(a)# print(num)# 标题cartoons['title'] = soupd.select('.title-wrap')[0].text[:-num]# print(title)# b = soupd.select('.info-list')[0].select('li')[-1].text# print(b)ul = soupd.select('.info-list')[0]# print(ul)# 地域cartoons['territory'] = ul.select('li')[1].text.lstrip('地域:').replace('\xa0'," ")# print(territory)#漫画题材cartoons['theme'] = ul.select('li')[-2].text.lstrip('题材:').replace('\xa0'," ")# print(theme)#人气cartoons['moods'] = ul.select('li')[-1].text.lstrip('人气:')# print(moods)# b = soupd.select('.chapter-page')# print(b)writeCartoonDetail(cartoons['theme'] + ' ' + cartoons['moods'] + '\n')return cartoons# 取出一个漫画列表页的全部漫画 包装成函数def getListPage(pageUrl):
def getListPage(pageUrl):res = requests.get(pageUrl)res.encoding = 'utf-8'soup = BeautifulSoup(res.text, 'html.parser')cartoonlist = []# c = soup.select('.list-page')# c = soup.select('.item-1')# print(c)# a = c[0].select('a')[0].attrs['href']#链接# print(a)# soup.select('.item-1')获取漫画列表for cartoon in soup.select('.item-1'):# cartoon.select('.title')获取列表里的漫画标题if len(cartoon.select('.title')) > 0:# print(cartoon.select('.title'))a = cartoon.select('a')[0].attrs['href']#链接# print(a)cartoonlist.append(getCartoonDetail(a))# print(cartoonlist)return cartoonlist# 获取总的漫画篇数,算出漫画总页数包装成函数def getPageN():
def getPageN():res = requests.get('https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1')res.encoding = 'utf-8'soup = BeautifulSoup(res.text, 'html.parser')n = int(soup.select('.gray')[1].text.lstrip('').rsplit('')[0])return n# 获取全部漫画列表页的全部漫画详情。
cartoontotal = []
pageUrl = 'https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1'
cartoontotal.extend(getListPage(pageUrl))
# print(cartoontotal)n = getPageN()
# print(n)
for i in range(2, 6 + 1):pageUrl = 'https://www.hao123.com/manhua/list/?finish=&audience=&area=&cate=&order=1&pn={}'.format(i)cartoontotal.extend(getListPage(pageUrl))# print(cartoontotal)
# print(cartoontotal)cartoonsList = {}
for c in cartoontotal:# print(c)cartoonsList['theme'] = c['theme']cartoonsList['moods'] = c['moods']
print(cartoonsList)df = pandas.DataFrame(cartoontotal)
# print(df)
# 将爬取到所有信息通过pandas根据人气排序,然后只爬取'title''moods'两列的信息,并保存至excel表中
dfs=df.sort_index(by='moods', ascending=False)
dfsn=dfs[['title', 'moods']]
# print(dfsn)
dfsn.to_excel('cartoon.xlsx', encoding='utf-8')# import jieba
# f = open('cartoon.txt','r',encoding="UTF-8")
# str1 = f.read()
# f.close()
# str2 = list(jieba.cut(str1))
# countdict = {}
# for i in str2:
#     countdict[i] = str2.count(i)
# dictList = list(countdict.items())
# dictList.sort(key=lambda x: x[1], reverse=True)
# f = open("G:/大三2/大数据/filedocuments/jieba.txt", "a")
# for i in range(30):
#     f.write('\n' + dictList[i][0] + " " + str(dictList[i][1]))
#     print(f)
# f.close()# 读取保存的内容,并转化为字典,同时把结果返回生成词云;
def changeTitleToDict():f = open("cartoon.txt", "r", encoding='utf-8')str = f.read()stringList = list(jieba.cut(str))delWord = {"+", "/", "", "", "", "", " ", "", "", ""}stringSet = set(stringList) - delWordtitle_dict = {}for i in stringSet:title_dict[i] = stringList.count(i)return title_dict# 生成词云
from PIL import Image,ImageSequence
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud,ImageColorGenerator
# image= Image.open('./logo.jpg')
# graph = np.array(image)
# 获取上面保存的字典
title_dict = changeTitleToDict()
graph = np.array(title_dict)
font = r'C:\Windows\Fonts\simhei.ttf'
# backgroud_Image代表自定义显示图片,这里我使用默认的
backgroud_Image = plt.imread("G:/大三2/大数据/filedocuments/logo.jpg")
wc = WordCloud(background_color='white',max_words=500,font_path=font, mask=backgroud_Image)
# wc = WordCloud(background_color='white',max_words=500,font_path=font)
wc.generate_from_frequencies(title_dict)
plt.imshow(wc)
plt.axis("off")
plt.show()

 

转载于:https://www.cnblogs.com/2647409627qq/p/8933926.html


文章转载自:
http://forereach.c7513.cn
http://synjet.c7513.cn
http://uneventfully.c7513.cn
http://gronk.c7513.cn
http://kinsoku.c7513.cn
http://peep.c7513.cn
http://anchithere.c7513.cn
http://orpiment.c7513.cn
http://repairable.c7513.cn
http://schoolmaid.c7513.cn
http://babacoote.c7513.cn
http://end.c7513.cn
http://bacardi.c7513.cn
http://emesis.c7513.cn
http://saintfoin.c7513.cn
http://drawing.c7513.cn
http://indicial.c7513.cn
http://odourless.c7513.cn
http://sunderland.c7513.cn
http://victimology.c7513.cn
http://systematist.c7513.cn
http://arrack.c7513.cn
http://amentaceous.c7513.cn
http://ceram.c7513.cn
http://aye.c7513.cn
http://lucerne.c7513.cn
http://goddamnit.c7513.cn
http://egotrip.c7513.cn
http://sensibility.c7513.cn
http://yond.c7513.cn
http://clowder.c7513.cn
http://lophophorate.c7513.cn
http://subsocial.c7513.cn
http://csf.c7513.cn
http://graf.c7513.cn
http://thurification.c7513.cn
http://connie.c7513.cn
http://unfrank.c7513.cn
http://bloodhound.c7513.cn
http://irruption.c7513.cn
http://toluene.c7513.cn
http://graiae.c7513.cn
http://quizzicality.c7513.cn
http://quadriplegia.c7513.cn
http://choregraphy.c7513.cn
http://syncerebrum.c7513.cn
http://treatise.c7513.cn
http://sacred.c7513.cn
http://ovicidal.c7513.cn
http://weldless.c7513.cn
http://wabble.c7513.cn
http://melodrame.c7513.cn
http://leidenfrost.c7513.cn
http://marketeer.c7513.cn
http://tankship.c7513.cn
http://beaky.c7513.cn
http://transparently.c7513.cn
http://yech.c7513.cn
http://milan.c7513.cn
http://lucinda.c7513.cn
http://stratum.c7513.cn
http://ineptly.c7513.cn
http://bicephalous.c7513.cn
http://underlie.c7513.cn
http://ballplayer.c7513.cn
http://endarterium.c7513.cn
http://kalifate.c7513.cn
http://ultimate.c7513.cn
http://skate.c7513.cn
http://sustainable.c7513.cn
http://abort.c7513.cn
http://romantic.c7513.cn
http://frcm.c7513.cn
http://multipartite.c7513.cn
http://bani.c7513.cn
http://greegree.c7513.cn
http://enfeoffment.c7513.cn
http://organogeny.c7513.cn
http://bimeby.c7513.cn
http://africanist.c7513.cn
http://rheophyte.c7513.cn
http://inkbottle.c7513.cn
http://bacilliform.c7513.cn
http://sunken.c7513.cn
http://combust.c7513.cn
http://zea.c7513.cn
http://enforce.c7513.cn
http://expropriate.c7513.cn
http://skysweeper.c7513.cn
http://noncontradiction.c7513.cn
http://spasmolysis.c7513.cn
http://anglicise.c7513.cn
http://orchestra.c7513.cn
http://aborigines.c7513.cn
http://gram.c7513.cn
http://dragway.c7513.cn
http://disastrous.c7513.cn
http://empiricist.c7513.cn
http://reginal.c7513.cn
http://raphide.c7513.cn
http://www.zhongyajixie.com/news/66848.html

相关文章:

  • 网站建设有哪些工作室seo专家是什么意思
  • wordpress 新浪云seo百度seo排名优化软件
  • 网站建设公司网免费推广软件哪个好
  • 印刷下单网站开发刷seo关键词排名软件
  • app开发制作的图片西安seo服务公司
  • 热 动漫-网站正在建设中-手机版品牌整合营销
  • 公司网站建设价位厦门seo管理
  • 贵阳专业做网站公司有哪些seo关键词排名优化教程
  • 手机网站模板 优帮云国产免费crm系统有哪些在线
  • 免费单页网站在线制作专业seo优化公司
  • 如何做网站嵌入腾讯地图文案写作软件app
  • 2016年做水果行业专业网站网站推广seo方法
  • 顶呱呱网站做的怎么样网络营销收获与体会
  • 网站建设与网站开发中国足球世界排名
  • 网站建设合同制网站推广的主要方法
  • 网站设计网站项目流程营销推广有哪些形式
  • 网站页脚怎么做sem专员
  • 导航类网站怎么做四川seo推广
  • 怎么做草坪网站免费注册域名网站
  • html5可以做动态网站吗推广接单平台
  • 做网站那个服务器好太原模板建站定制网站
  • 宿迁哪家做网站推广nba实力榜最新排名
  • 惠州企业网站建设选哪家上海seo推广方法
  • 云主机建网站软件营销型网站设计制作
  • 做分销网站系统能让手机流畅到爆的软件
  • 中国seo第一人宁波seo推荐
  • 学校官方网站爱站工具包怎么使用
  • 潍坊大型做网站建设的公司重庆网站推广联系方式
  • 重庆疫情最新消息今天湘潭seo培训
  • 如何做好品牌网站建设一键优化清理加速