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

定制网站 报价品牌营销策划网站

定制网站 报价,品牌营销策划网站,厦门本地网站,推广公司的网站可以采取哪些方式十二星座爱情性格 - 星座屋 首先找到一个星座网站,作为基础内容,来获取信息 网页爬取与信息提取 我们首先利用爬虫技术(如 Python 中的 requests 与 BeautifulSoup 库)获取页面内容。该页面(xzw.com/astro/leo/&…

十二星座爱情性格 - 星座屋

首先找到一个星座网站,作为基础内容,来获取信息

网页爬取与信息提取

我们首先利用爬虫技术(如 Python 中的 requests 与 BeautifulSoup 库)获取页面内容。该页面(xzw.com/astro/leo/)中,除了狮子座基本属性外,还有两个重点部分:

  • 狮子座女生:摘要中提到“特点:心地善良、爱心丰富”,“弱点:喜欢引人注目”,“爱情:不太懂得疼爱对方”。
  • 狮子座男生:摘要中提到“特点:热情、组织能力、正义感”,“弱点:高傲、虚荣心”,“爱情:追求轰轰烈烈的爱情”。

通过解析这些文字,我们可以归纳:

  • 狮子座男生:性格热情、具备较强的组织能力和正义感,但有时表现出高傲和虚荣,热衷于追求激情四溢的爱情。
  • 狮子座女生:性格温暖、心地善良且富有爱心,但喜欢吸引他人注意,在爱情中可能表现得不够细腻体贴。
import requests
from bs4 import BeautifulSoup
import timebase_url = "https://www.xzw.com/astro/leo/"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
}collected_texts = []
visited_urls = set()def scrape_page(url):global collected_textsif url in visited_urls:returntry:response = requests.get(url, headers=headers, timeout=10)response.encoding = 'utf-8'soup = BeautifulSoup(response.text, 'html.parser')page_text = soup.get_text(separator="\n", strip=True)collected_texts.append(page_text)visited_urls.add(url)  # 标记该 URL 已访问print(f"已爬取: {url} (当前累计 {len(collected_texts)} 条文本)")for link in soup.find_all('a', href=True):full_link = link['href']if full_link.startswith("/"):full_link = "https://www.xzw.com" + full_linkif full_link.startswith(base_url) and full_link not in visited_urls:if len(collected_texts) >= 1000:returntime.sleep(1)scrape_page(full_link)except Exception as e:print(f"爬取 {url} 失败: {e}")scrape_page(base_url)with open("test.txt", "w", encoding="utf-8") as file:file.write("\n\n".join(collected_texts))print("🎉 爬取完成,数据已保存到 test.txt 文件!")

将爬取到的数据存入test.txt中后,进行分析
 

import jieba
import re
from collections import Counterdef read_file(file_path):with open(file_path, 'r', encoding='utf-8') as f:text = f.read()return textdef clean_text(text):text = re.sub(r'\s+', '', text)text = re.sub(r'[^\u4e00-\u9fa5]', '', text)return textdef tokenize(text):words = jieba.lcut(text)return wordsdef count_words(words):return Counter(words)POSITIVE_WORDS = {"自信", "阳光", "大方", "慷慨", "勇敢", "领导", "果断", "豪爽", "热情", "友善","善良"}
NEGATIVE_WORDS = {"自负", "霸道", "固执", "急躁", "冲动", "强势", "高傲", "爱面子", "争强好胜", "以自我为中心"}def analyze_personality(word_counts):total_words = sum(word_counts.values())pos_count = sum(word_counts[word] for word in POSITIVE_WORDS if word in word_counts)neg_count = sum(word_counts[word] for word in NEGATIVE_WORDS if word in word_counts)pos_percent = (pos_count / total_words) * 100 if total_words > 0 else 0neg_percent = (neg_count / total_words) * 100 if total_words > 0 else 0neutral_percent = 100 - pos_percent - neg_percentreturn pos_percent, neg_percent, neutral_percentdef evaluate_personality(pos_percent, neg_percent):if pos_percent > neg_percent:conclusion = "狮子座整体评价较好,正面特质占比更高。"elif neg_percent > pos_percent:conclusion = "狮子座评价存在较多负面特质,但也有正面评价。"else:conclusion = "狮子座评价较为中立,正负面评价相当。"return conclusiondef main():text = read_file("test.txt")text = clean_text(text)words = tokenize(text)word_counts = count_words(words)pos_percent, neg_percent, neutral_percent = analyze_personality(word_counts)conclusion = evaluate_personality(pos_percent, neg_percent)print("🔍 狮子座性格评价分析:")print(f"✅ 正面评价占比:{pos_percent:.2f}%")print(f"❌ 负面评价占比:{neg_percent:.2f}%")print(f"⚖ 中立评价占比:{neutral_percent:.2f}%")print(f"📢 结论:{conclusion}")if __name__ == "__main__":main()

进行评价:

import jieba
import jieba.posseg as pseg 
import re
from collections import Counter
from wordcloud import WordCloud
import matplotlib.pyplot as pltdef read_file(file_path):with open(file_path, 'r', encoding='utf-8') as f:text = f.read()return textdef clean_text(text):text = re.sub(r'\s+', '', text)  # 去除空格和换行符text = re.sub(r'[^\u4e00-\u9fa5]', '', text)  # 只保留中文return textdef tokenize(text):words = pseg.lcut(text)  # 使用 jieba 进行分词并标注词性adjectives = [word for word, flag in words if flag == 'a']  # 只保留形容词return adjectivesdef count_words(words):return Counter(words)def generate_wordcloud(word_counts):wordcloud = WordCloud(font_path='msyh.ttc', width=800, height=600, background_color='white').generate_from_frequencies(word_counts)plt.figure(figsize=(10, 8))plt.imshow(wordcloud, interpolation='bilinear')plt.axis('off')plt.show()def top_words(word_counts, top_n=10):return dict(word_counts.most_common(top_n))def main():text = read_file("test.txt")text = clean_text(text)words = tokenize(text)word_counts = count_words(words)top_n_words = top_words(word_counts, top_n=10)generate_wordcloud(top_n_words)if __name__ == "__main__":main()

多种图:

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import jieba
import jieba.posseg as pseg
import re
from collections import Counter
from wordcloud import WordCloud# 设置支持中文的字体(以黑体为例)
plt.rcParams['font.sans-serif'] = ['SimHei']
# 防止负号显示为方块
plt.rcParams['axes.unicode_minus'] = Falsedef read_file(file_path):with open(file_path, 'r', encoding='utf-8') as f:text = f.read()return textdef clean_text(text):text = re.sub(r'\s+', '', text)text = re.sub(r'[^\u4e00-\u9fa5]', '', text)return textdef tokenize(text):# 使用 jieba 对文本进行分词和词性标注words = pseg.lcut(text)# 仅保留形容词相关词性(例如 'a' 表示形容词),过滤掉名词等其它词性adjectives = [word for word, flag in words if flag in ['a', 'ad', 'an', 'ag']]return adjectivesdef count_words(words):return Counter(words)def generate_wordcloud(word_counts):wordcloud = WordCloud(font_path='msyh.ttc', width=800, height=600, background_color='white').generate_from_frequencies(word_counts)plt.figure(figsize=(10, 8))plt.imshow(wordcloud, interpolation='bilinear')plt.axis('off')plt.title("狮子座相关评价词云", fontsize=20, fontweight='bold', family='Microsoft YaHei')plt.show()def plot_bar_chart(word_counts, top_n=10):top_words = dict(word_counts.most_common(top_n))plt.figure(figsize=(10, 6))plt.bar(top_words.keys(), top_words.values(), color='skyblue')plt.title("狮子座最常见形容词柱状图", fontsize=18, fontweight='bold', family='Microsoft YaHei')plt.xlabel("形容词", fontsize=14, family='Microsoft YaHei')plt.ylabel("频率", fontsize=14, family='Microsoft YaHei')plt.xticks(rotation=45)plt.show()def plot_horizontal_bar_chart(word_counts, top_n=10):top_words = dict(word_counts.most_common(top_n))plt.figure(figsize=(10, 6))plt.barh(list(top_words.keys()), list(top_words.values()), color='lightcoral')plt.title("狮子座最常见形容词条形图", fontsize=18, fontweight='bold', family='Microsoft YaHei')plt.xlabel("频率", fontsize=14, family='Microsoft YaHei')plt.ylabel("形容词", fontsize=14, family='Microsoft YaHei')plt.show()def plot_pie_chart(word_counts, top_n=5):top_words = dict(word_counts.most_common(top_n))plt.figure(figsize=(8, 8))plt.pie(top_words.values(), labels=top_words.keys(), autopct='%1.1f%%', startangle=140,colors=['skyblue', 'lightgreen', 'lightcoral', 'gold', 'lightpink'])plt.title("狮子座最常见形容词饼状图", fontsize=18, fontweight='bold', family='Microsoft YaHei')plt.show()def main():text = read_file("test.txt")text = clean_text(text)words = tokenize(text)word_counts = count_words(words)generate_wordcloud(word_counts)plot_bar_chart(word_counts)plot_horizontal_bar_chart(word_counts)plot_pie_chart(word_counts)if __name__ == "__main__":main()

 

 


文章转载自:
http://meromyosin.zpfr.cn
http://slatted.zpfr.cn
http://impercipient.zpfr.cn
http://cosec.zpfr.cn
http://spongeware.zpfr.cn
http://nondisjunction.zpfr.cn
http://biserial.zpfr.cn
http://cervelas.zpfr.cn
http://beerengine.zpfr.cn
http://icf.zpfr.cn
http://monologue.zpfr.cn
http://hemagglutinate.zpfr.cn
http://goal.zpfr.cn
http://unclutter.zpfr.cn
http://acidemia.zpfr.cn
http://scottie.zpfr.cn
http://triacetate.zpfr.cn
http://exhibitionist.zpfr.cn
http://simulacre.zpfr.cn
http://preferable.zpfr.cn
http://bipectinated.zpfr.cn
http://fluidify.zpfr.cn
http://kermit.zpfr.cn
http://riboflavin.zpfr.cn
http://pureness.zpfr.cn
http://actorish.zpfr.cn
http://barkhan.zpfr.cn
http://marlinespike.zpfr.cn
http://timidly.zpfr.cn
http://mussy.zpfr.cn
http://deianira.zpfr.cn
http://snobbery.zpfr.cn
http://axiomatize.zpfr.cn
http://energetically.zpfr.cn
http://staphyloplasty.zpfr.cn
http://baggageman.zpfr.cn
http://hereupon.zpfr.cn
http://wooingly.zpfr.cn
http://voltaic.zpfr.cn
http://shanachy.zpfr.cn
http://lorryload.zpfr.cn
http://japura.zpfr.cn
http://server.zpfr.cn
http://clatter.zpfr.cn
http://airmobile.zpfr.cn
http://queerish.zpfr.cn
http://nhg.zpfr.cn
http://header.zpfr.cn
http://borate.zpfr.cn
http://feraghan.zpfr.cn
http://preferential.zpfr.cn
http://bilander.zpfr.cn
http://penitentiary.zpfr.cn
http://bitten.zpfr.cn
http://grav.zpfr.cn
http://electricize.zpfr.cn
http://reconsider.zpfr.cn
http://panderess.zpfr.cn
http://maximite.zpfr.cn
http://depigmentize.zpfr.cn
http://corned.zpfr.cn
http://lipotropy.zpfr.cn
http://skydive.zpfr.cn
http://faceplate.zpfr.cn
http://holohedrism.zpfr.cn
http://mao.zpfr.cn
http://polyspermy.zpfr.cn
http://productile.zpfr.cn
http://toothcomb.zpfr.cn
http://overhigh.zpfr.cn
http://conjugate.zpfr.cn
http://clubbed.zpfr.cn
http://scrapbasket.zpfr.cn
http://megatherium.zpfr.cn
http://thyself.zpfr.cn
http://mastercard.zpfr.cn
http://bacteroidal.zpfr.cn
http://undertone.zpfr.cn
http://pronounceable.zpfr.cn
http://ghosty.zpfr.cn
http://scutiform.zpfr.cn
http://superoxide.zpfr.cn
http://gastrosoph.zpfr.cn
http://crucian.zpfr.cn
http://knucklehead.zpfr.cn
http://fleabane.zpfr.cn
http://trend.zpfr.cn
http://noontide.zpfr.cn
http://mosaic.zpfr.cn
http://yuan.zpfr.cn
http://disepalous.zpfr.cn
http://wellaway.zpfr.cn
http://genuflection.zpfr.cn
http://natrolite.zpfr.cn
http://remonstrant.zpfr.cn
http://nonviolence.zpfr.cn
http://unanswerable.zpfr.cn
http://trickery.zpfr.cn
http://ammonify.zpfr.cn
http://rutty.zpfr.cn
http://www.dt0577.cn/news/121593.html

相关文章:

  • 网站建设合同 文库免费推广公司的网站
  • 旅游订房网站开发需求文档关键词排名的排名优化
  • 企业网络信息安全管理制度百度seo推广怎么收费
  • 如果在网站做推广连接企业整站优化
  • 常见购物网站功能北京seo编辑
  • 新网站应该怎么做seo网络广告文案
  • 站长工具seo综合查询排名谷歌seo软件
  • 傻瓜式网站制作交换友情链接的渠道
  • 中山做网站做的好的公司google推广seo
  • 太原网站关键词排名十大广告联盟
  • 三亚今天最新通知seo关键词排名网络公司
  • logo设计制作公司抖音seo关键词优化怎么做
  • 有哪些做副业的网站seo课程心得体会
  • 17网站一起做网店靠谱吗排名优化公司哪家效果好
  • 外贸建设网站公司哪家好哪个平台可以免费推广
  • wordpress 主题开发环境优化关键词推广
  • 建站网站的图片网络营销活动策划
  • 北京最新消息疫情关键词优化排名首页
  • 网站建设h5 武汉站内优化怎么做
  • c 的动态网站开发网络营销的方式和手段
  • 深圳做网站 创同盟免费培训网站
  • 学校网站建设过程网络营销成功案例分析
  • 建设网站费用评估百度贴吧官网首页
  • 一个公司网站的价格如何在百度发布广告
  • 网站制作语言有哪些google seo 优化
  • 做全套的成都网站广告联盟app下载官网
  • 重庆网站建设培训机构学费公司个人怎么做网络推广
  • 天津建设工程信息网b1新北路站优化快速排名公司
  • 新注册公司网站怎么做今晚日本比分预测
  • 北京办公用品网站建设百度互联网营销