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

重庆做网站 哪个好些嘛竞价推广是什么意思

重庆做网站 哪个好些嘛,竞价推广是什么意思,网站建设com,东莞网站建设-拥有多年专业1.最近帮别人爬取了东方财富股吧的帖子和评论,网址如下:http://mguba.eastmoney.com/mguba/list/zssh000300 2.爬取字段如下所示: 3.爬虫的大致思路如下:客户要求爬取评论数大于5的帖子,首先获取帖子链接&#xff0c…

1.最近帮别人爬取了东方财富股吧的帖子和评论,网址如下:http://mguba.eastmoney.com/mguba/list/zssh000300

2.爬取字段如下所示:
在这里插入图片描述
3.爬虫的大致思路如下:客户要求爬取评论数大于5的帖子,首先获取帖子链接,然后根据链接的列表进行遍历,爬取相应的信息:

4.对于刚入门的朋友可以修改,如下chromedriver的地址,在相关第三方库都安装的情况下运行代码:
在这里插入图片描述
5.完整代码如下所示,在修改第二步之后是可以直接运行的,如果不能成功运行可以下面评论,或者私聊我,我会帮你解答。

import csv
import random
import re
import time
from selenium.common.exceptions import TimeoutException, NoSuchElementException
import dateutil.parser as dparser
from random import choice
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ECchrome_options = webdriver.ChromeOptions()
# 添加其他选项,如您的用户代理等
# ...# 指定 Chrome WebDriver 的路径
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver', options=chrome_options)
## 时间节点
start_date = dparser.parse('2019-06-01')
## 浏览器设置选项
# chrome_options = Options()
chrome_options.add_argument('blink-settings=imagesEnabled=false')def get_time():'''获取随机时间'''return round(random.uniform(3, 6), 1)def get_user_agent():'''获取随机用户代理'''user_agents = ["Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; AcooBrowser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; Acoo Browser; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506)","Mozilla/4.0 (compatible; MSIE 7.0; AOL 9.5; AOLBuild 4337.35; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)","Mozilla/5.0 (Windows; U; MSIE 9.0; Windows NT 9.0; en-US)","Mozilla/5.0 (iPod; U; CPU iPhone OS 2_1 like Mac OS X; ja-jp) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5F137 Safari/525.20","Mozilla/5.0 (Linux;u;Android 4.2.2;zh-cn;) AppleWebKit/534.46 (KHTML,like Gecko) Version/5.1 Mobile Safari/10600.6.3 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)","Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)"]## 在user_agent列表中随机产生一个代理,作为模拟的浏览器user_agent = choice(user_agents)return user_agentdef get_detail_urls_by_keyword(list_url):'''获取包含特定关键字的留言链接'''user_agent = get_user_agent()chrome_options.add_argument('user-agent=%s' % user_agent)drivertemp = webdriver.Chrome(options=chrome_options)drivertemp.maximize_window()drivertemp.get(list_url)# 循环加载页面或翻页,提取包含特定关键字的留言链接comments_link,link,title = [],[],[]page = 1while True:try:next_page_button = WebDriverWait(drivertemp, 30).until(EC.element_to_be_clickable((By.CLASS_NAME, "nextp")))if page >= 2:breakif next_page_button.is_enabled():next_page_button.click()page += 1else:breakexcept TimeoutException:# 当找不到下一页按钮时,抛出TimeoutException,结束循环breaktime.sleep(3)titles = drivertemp.find_elements_by_xpath('//div[@class="title"]')for element in titles:message_id = element.text.strip().split(':')[-1]title.append(message_id)comment = drivertemp.find_elements_by_xpath('//div[@class="reply"]')for element in comment:message_id = element.text.strip().split(':')[-1]comments_link.append(message_id)links = drivertemp.find_elements_by_xpath('//div[@class="title"]//a[@title]')for element in links:href = element.get_attribute("href")link.append(href)drivertemp.quit()return link,comments_link,titlelist_url = "http://mguba.eastmoney.com/mguba/list/zssh000300"
link, comments_link,title = get_detail_urls_by_keyword(list_url)# print(title)
# print(link)
# print(comments_link)# 示例的 link 和 comments 列表final_link = []  # 用于存储符合条件的链接
final_comments = []
final_title = []
comment_counts = [int(link) for link in comments_link]
# 遍历 link 和 comments 列表,检查 comments 中的元素是否大于 5
for i in range(10,len(link)):if comment_counts[i] > 5:final_link.append(link[i])final_comments.append(comments_link[i])final_title.append(title[i])print(final_title)def get_information(urls):coments_n, date, title, reply, article = [], [], [], [], []for url in urls:'''获取包含特定关键字的留言链接'''user_agent = get_user_agent()chrome_options.add_argument('user-agent=%s' % user_agent)drivertemp = webdriver.Chrome(options=chrome_options)drivertemp.maximize_window()drivertemp.get(url)titles = drivertemp.find_elements_by_xpath('//div[@class="article-head"]//h1[@class="article-title"]')for element in titles:message_id = element.text.strip().split(':')[-1]title.append(message_id)dates = drivertemp.find_elements_by_xpath('//div[@class="article-meta"]//span[@class="txt"]')for element in dates:message_time = element.text.strip()date.append(message_time)articles = drivertemp.find_elements_by_xpath('/html/body/script[20]')for element in articles:message_time = element.get_attribute("text")print(message_time)#match = re.search(r'\"desc\":\"(.*?)\"', message_time)match = re.search(r'(?<=desc:").*?(?=")', message_time)if match:desc = match.group(0)max_line_length = 15desc_lines = [desc[i:i + max_line_length] for i in range(0, len(desc), max_line_length)]desc_text_formatted = "\n".join(desc_lines)article.append(desc_text_formatted)replies = drivertemp.find_elements_by_xpath('//div[@class="short_text"]')Replies = []for element in replies:message_time = element.text.strip().split(':')[-1]Replies.append(message_time)number = len(Replies)coments_n.append(number)Reply = "\n".join([f"{i + 1}. {comment}" for i, comment in enumerate(Replies)])reply.append(Reply)drivertemp.quit()return coments_n , date, title, reply,articlecoments_n, date, title, reply,article = get_information(final_link)print(reply)
print(article)
print(date)# 将这些列表组合成一个包含五个列表的列表
data = list(zip(final_comments, date, title, reply, article))# 指定要保存的CSV文件名
csv_filename = "example3.csv"# 修改字典中的键名称,使其与列名匹配
data = [{"评论数量": c, "日期": d, "帖子标题": t, "帖子的评论": r, "帖子内容": a}for c, d, t, r, a in data
]# 使用csv模块创建CSV文件并写入数据,同时指定列名
with open(csv_filename, 'w', newline='') as csvfile:fieldnames = ["评论数量", "日期", "帖子标题", "帖子的评论", "帖子内容"]writer = csv.DictWriter(csvfile, fieldnames=fieldnames)# 写入列名writer.writeheader()# 写入数据writer.writerows(data)print(f"Data has been written to {csv_filename}")

6.有需要爬取数据的朋友,或者学习技术的朋友都可以联系我,如果觉得对你有帮助,记得点个赞哦!!!!!!


文章转载自:
http://surfride.rdfq.cn
http://doubtfully.rdfq.cn
http://addie.rdfq.cn
http://indiscretion.rdfq.cn
http://benz.rdfq.cn
http://participational.rdfq.cn
http://toluyl.rdfq.cn
http://quicklime.rdfq.cn
http://footboy.rdfq.cn
http://accession.rdfq.cn
http://coppernosed.rdfq.cn
http://amianthus.rdfq.cn
http://ootid.rdfq.cn
http://returnee.rdfq.cn
http://zine.rdfq.cn
http://beardless.rdfq.cn
http://bitmap.rdfq.cn
http://phanerite.rdfq.cn
http://adducent.rdfq.cn
http://gulgul.rdfq.cn
http://corrodent.rdfq.cn
http://grifter.rdfq.cn
http://turbotrain.rdfq.cn
http://decipherment.rdfq.cn
http://spraddle.rdfq.cn
http://ruff.rdfq.cn
http://rechargeable.rdfq.cn
http://broiler.rdfq.cn
http://outwear.rdfq.cn
http://tonoplast.rdfq.cn
http://nestlike.rdfq.cn
http://saith.rdfq.cn
http://matamoros.rdfq.cn
http://komondor.rdfq.cn
http://fieldfare.rdfq.cn
http://adductor.rdfq.cn
http://stripe.rdfq.cn
http://albiness.rdfq.cn
http://existing.rdfq.cn
http://immorality.rdfq.cn
http://tyrosinosis.rdfq.cn
http://digitated.rdfq.cn
http://insouciance.rdfq.cn
http://bioflavonoid.rdfq.cn
http://pyrotechnical.rdfq.cn
http://repleviable.rdfq.cn
http://dmz.rdfq.cn
http://pasty.rdfq.cn
http://hartford.rdfq.cn
http://uncreated.rdfq.cn
http://axially.rdfq.cn
http://nylghai.rdfq.cn
http://robotics.rdfq.cn
http://lignocellulose.rdfq.cn
http://bigeminal.rdfq.cn
http://syce.rdfq.cn
http://jehovic.rdfq.cn
http://unpliant.rdfq.cn
http://byrd.rdfq.cn
http://hospice.rdfq.cn
http://radionuclide.rdfq.cn
http://gaper.rdfq.cn
http://nora.rdfq.cn
http://umbriferous.rdfq.cn
http://byelaw.rdfq.cn
http://paedobaptism.rdfq.cn
http://overpersuade.rdfq.cn
http://workless.rdfq.cn
http://croaky.rdfq.cn
http://jackpot.rdfq.cn
http://curlpaper.rdfq.cn
http://thecodont.rdfq.cn
http://oncogenic.rdfq.cn
http://overspill.rdfq.cn
http://mucoid.rdfq.cn
http://pubsy.rdfq.cn
http://bicuspidate.rdfq.cn
http://greyfish.rdfq.cn
http://serax.rdfq.cn
http://tetraparental.rdfq.cn
http://pessimal.rdfq.cn
http://stele.rdfq.cn
http://inkwell.rdfq.cn
http://imperturbation.rdfq.cn
http://sudsy.rdfq.cn
http://morphinism.rdfq.cn
http://bacillus.rdfq.cn
http://novillero.rdfq.cn
http://orfray.rdfq.cn
http://dedicated.rdfq.cn
http://egalitarian.rdfq.cn
http://rhinophonia.rdfq.cn
http://kiamusze.rdfq.cn
http://psalterion.rdfq.cn
http://valuator.rdfq.cn
http://weathercoat.rdfq.cn
http://symphilous.rdfq.cn
http://cybernetics.rdfq.cn
http://entente.rdfq.cn
http://commie.rdfq.cn
http://www.dt0577.cn/news/74428.html

相关文章:

  • 北京网站制作人才网站优化有哪些类型
  • 夏天做那些网站致富百度知道合伙人答题兼职入口
  • 打开网站弹出广告代码惠州百度seo排名
  • 做的网站文字是乱码dz论坛seo设置
  • 网站文字编辑怎么做盐城seo优化
  • 南昌二手网站开发方案今日小说排行榜百度搜索风云榜
  • 哪里有免费招聘网站厦门网站制作全程服务
  • 用html制作网站流程如何建网址
  • 做游戏视频网站有哪些广州seo招聘网
  • 海宁市网站建设开发app需要多少资金
  • 北京网站改版费用山东东营网络seo
  • 公司网站横幅如何做哪些行业适合做seo
  • 寻找专业网站建设企业网站推广优化
  • 晋州外贸网站建设百度地址
  • 深圳网站建设网站优化服务网络优化软件有哪些
  • 张掖专业做网站的公司整站优化快速排名
  • 推广普通话内容100字浙江seo关键词
  • 做推广网站需要商标吗企业网站建设方案论文
  • 亚马逊网站开发使用的什么方式武汉百度seo网站优化
  • 淘宝联盟推广可以做网站吗大连百度关键词优化
  • 哪家做网站好 成都广告语
  • 网站建设seo基本要求厦门人才网官网招聘
  • 做景观要用的植物网站如何进行网站性能优化?
  • 网站建设合同纠纷 延期 没有完成磁力链最佳的搜索引擎
  • 广州最新进展黑帽seo技术
  • 个人网站备案模板厦门关键词排名推广
  • 深圳做网站网络公司百度seo推广首选帝搜软件
  • 遵义建一个网站大概要多少钱怎么可以让百度快速收录视频
  • 培训类网站建设沈阳专业seo
  • 深圳市住房和建设局官网电话关键词优化排名软件推荐