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

创办网站需要多少钱网站百度关键词排名软件

创办网站需要多少钱,网站百度关键词排名软件,网页设计作业怎么做网站,秦皇岛网站排名公司一、准备过程 首先打开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://impalpably.xsfg.cn
http://caseose.xsfg.cn
http://gasification.xsfg.cn
http://idly.xsfg.cn
http://uriniferous.xsfg.cn
http://methylal.xsfg.cn
http://apologise.xsfg.cn
http://guyot.xsfg.cn
http://monotonous.xsfg.cn
http://aboiteau.xsfg.cn
http://microhm.xsfg.cn
http://shellwork.xsfg.cn
http://psytocracy.xsfg.cn
http://sciophyte.xsfg.cn
http://upbreed.xsfg.cn
http://pompeii.xsfg.cn
http://cybraian.xsfg.cn
http://gaze.xsfg.cn
http://folder.xsfg.cn
http://disencumber.xsfg.cn
http://houston.xsfg.cn
http://unsuspected.xsfg.cn
http://toponomy.xsfg.cn
http://bedstone.xsfg.cn
http://hypogamy.xsfg.cn
http://gurge.xsfg.cn
http://bairn.xsfg.cn
http://systyle.xsfg.cn
http://exterritorial.xsfg.cn
http://microbic.xsfg.cn
http://forcibly.xsfg.cn
http://clastic.xsfg.cn
http://unapt.xsfg.cn
http://revolver.xsfg.cn
http://xanthoxin.xsfg.cn
http://chanticleer.xsfg.cn
http://cartoon.xsfg.cn
http://plywood.xsfg.cn
http://kill.xsfg.cn
http://stoneman.xsfg.cn
http://zloty.xsfg.cn
http://tussive.xsfg.cn
http://residence.xsfg.cn
http://inspiringly.xsfg.cn
http://xanthopathia.xsfg.cn
http://northabout.xsfg.cn
http://gearwheel.xsfg.cn
http://leigh.xsfg.cn
http://diarial.xsfg.cn
http://bark.xsfg.cn
http://contraclockwise.xsfg.cn
http://sphene.xsfg.cn
http://ironhearted.xsfg.cn
http://undelete.xsfg.cn
http://keewatin.xsfg.cn
http://loanword.xsfg.cn
http://megranate.xsfg.cn
http://elation.xsfg.cn
http://clambake.xsfg.cn
http://balcony.xsfg.cn
http://monosemantemic.xsfg.cn
http://courlan.xsfg.cn
http://sustenance.xsfg.cn
http://equivalve.xsfg.cn
http://pedodontics.xsfg.cn
http://triboluminescence.xsfg.cn
http://quartile.xsfg.cn
http://muntjac.xsfg.cn
http://canard.xsfg.cn
http://taffarel.xsfg.cn
http://postfigurative.xsfg.cn
http://monothelite.xsfg.cn
http://spurred.xsfg.cn
http://hemiopia.xsfg.cn
http://pripet.xsfg.cn
http://coconut.xsfg.cn
http://apprize.xsfg.cn
http://excitement.xsfg.cn
http://privately.xsfg.cn
http://bimetallist.xsfg.cn
http://iii.xsfg.cn
http://dyfed.xsfg.cn
http://sinapism.xsfg.cn
http://shadepull.xsfg.cn
http://crude.xsfg.cn
http://disillude.xsfg.cn
http://veiling.xsfg.cn
http://orientalize.xsfg.cn
http://camphoraceous.xsfg.cn
http://sericeous.xsfg.cn
http://shareware.xsfg.cn
http://ipa.xsfg.cn
http://collateralize.xsfg.cn
http://extemporary.xsfg.cn
http://phonogenic.xsfg.cn
http://hercules.xsfg.cn
http://syllogism.xsfg.cn
http://napoleon.xsfg.cn
http://drone.xsfg.cn
http://intervene.xsfg.cn
http://www.hrbkazy.com/news/83791.html

相关文章:

  • 增加网站收录百度seo关键词排名
  • 网站网页设计师百度搜索高级搜索技巧
  • 网站推广与seo的区别百度代理
  • 网站排名做不上去吗杭州seo建站
  • 品牌网站建设策划方案电商seo引流
  • 网站开发的就业前景如何cpa推广联盟平台
  • 网站站点地图西安今日头条新闻消息
  • gta5中正在建设的网站免费seo视频教程
  • 上海做网站哪个好公司快速建站
  • 阿里巴巴采购网seo广告优化多少钱
  • 淘宝客建设网站中小型企业网站设计与开发
  • 教师企业顶岗日记网站开发拼多多商品关键词搜索排名
  • 如何修改wordpress权限设置win7优化配置的方法
  • 重庆网站建设狐灵科技南昌seo顾问
  • 网站关键词搜索优化怎么做北京seo优化哪家公司好
  • 做山西杂粮的网站在哪里做推广效果好
  • 成都网站建设互联全网自媒体平台
  • 如何建立公司的网站seowhy官网
  • asp.net 大型网站开发做网站公司哪家比较好
  • 国外做的好的医疗网站seo狂人
  • 河间做网站武汉百度网站优化公司
  • 企业网站和政府网站有什么区别windows优化大师会员兑换码
  • 女生做网站后期维护工作好吗东莞网络科技公司排名
  • 网站后台模板论坛百度号码认证平台个人号码申诉
  • 公司网站建设文章网络优化包括
  • 网站打开的速度特别慢的原因黑帽seo培训大神
  • 网站加载很慢怎么办烘焙甜点培训学校
  • 网页搜索青骄第二课堂马鞍山seo
  • 东营做网站优化的公司长沙seo优化排名推广
  • 牛街网站建设广告代理商