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

广州的网站建设公司深圳建设交易工程信息网

广州的网站建设公司,深圳建设交易工程信息网,sql如何建设网站数据库,semseo是什么意思1.从新闻url获取新闻详情#xff1a; 字典,anews 2.从列表页的url获取新闻url#xff1a;列表append(字典) alist 3.生成所页列表页的url并获取全部新闻 #xff1a;列表extend(列表) allnews *每个同学爬学号尾数开始的10个列表页 4.设置合理的爬取间隔 import time import…1.从新闻url获取新闻详情 字典,anews 2.从列表页的url获取新闻url列表append(字典) alist 3.生成所页列表页的url并获取全部新闻 列表extend(列表) allnews *每个同学爬学号尾数开始的10个列表页 4.设置合理的爬取间隔 import time import random time.sleep(random.random()*3) 5.用pandas做简单的数据处理并保存 保存到csv或excel文件  newsdf.to_csv(rF:\duym\爬虫\gzccnews.csv) 保存到数据库 import sqlite3with sqlite3.connect(gzccnewsdb.sqlite) as db:    newsdf.to_sql(gzccnewsdb,db) # -*- coding: utf-8 -*-Created on Thu Apr 11 12:33:03 2019author: Administrator import requests from bs4 import BeautifulSoup from datetime import datetime import re import pandas as pd import time import random import sqlite3newsUrl http://news.gzcc.cn/html/2005/xiaoyuanxinwen_0710/4.html listUrl http://news.gzcc.cn/html/xiaoyuanxinwen/def click(url):id re.findall((\d{1,5}), url)[-1]clickUrl http://oa.gzcc.cn/api.php?opcountid{}modelid80.format(id)resClick requests.get(clickUrl)newsClick int(resClick.text.split(.html)[-1].lstrip(().rstrip();))return newsClickdef newsdt(showinfo):newsDate showinfo.split()[0].split(:)[1]newsTime showinfo.split()[1]newsDT newsDate newsTimedt datetime.strptime(newsDT, %Y-%m-%d %H:%M:%S)return dtdef anews(url)newsDetail {}res requests.get(url)res.encoding utf-8soup BeautifulSoup(res.text, html.parser)newsDetail[newsTitle] soup.select(.show-title)[0].textshowinfo soup.select(.show-info)[0].textnewsDetail[newsDT] newsdt(showinfo)newsDetail[newsClick] click(newsUrl)return newsDetaildef alist(url):res requests.get(listUrl)res.encoding utf-8soup BeautifulSoup(res.text, html.parser)newsList []for news in soup.select(li):if len(news.select(.news-list-title)) 0:newsUrl news.select(a)[0][href]newsDesc news.select(.news-list-description)[0].textnewsDict anews(newsUrl)newsDict[description] newsDescnewsList.append(newsDict)return newsListalist(listUrl)alist(newsUrl) res requests.get(http://news.gzcc.cn/html/xiaoyuanxinwen/) res.encoding utf-8 soup BeautifulSoup(res.text, html.parser)for news in soup.select(li):if len(news.select(.news-list-title)) 0:newsUrl news.select(a)[0][href]print(anews(newsUrl))allnews [] for i in range(57, 67):listUrl http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html.format(i)allnews.extend(alist(listUrl))print(allnewsLength{}.format(len(allnews))) print(allnews)res requests.get(http://news.gzcc.cn/html/xiaoyuanxinwen/) res.encoding utf-8 soup BeautifulSoup(res.text, html.parser) for news in soup.select(li):if len(news.select(.news-list-title)) 0:newsUrl news.select(a)[0][href]print(anews(newsUrl))s1 pd.Series([100, 23, bugingcode]) print(s1) pd.Series(anews) newsdf pd.DataFrame(allnews) for i in range(5):print(i)time.sleep(random.random() * 3)print(newsdf)newsdf.to_csv(rD:\py_file\gzcc.csv,encodingutf_8_sig)with sqlite3.connect(rD:\py_file\gzccnewsdb.sqlite) as db:newsdf.to_sql(gzccnewsdb,db)转载于:https://www.cnblogs.com/gswyz/p/10688905.html
http://wiki.neutronadmin.com/news/310101/

相关文章:

  • 网站建设全包需要多少钱做网站 赚钱
  • 洪洞网站建设汕头搜索引擎优化服务
  • 2017网站开发就业前景农产品网络营销推广方案
  • 网站建设推推蛙培训学校网站系统
  • 做网站和做app哪个贵wordpress图片调方法
  • 上海网站建设网页制福田做网站公司怎么选
  • 如何在云服务器上搭建网站哪家公司网站做得好
  • 网站子站建设企业专属空间官网
  • 上海做网站的公司有哪些免费加客源
  • 永康做网站的北京网约车
  • 做网站的宣传语90设计官方
  • 在网站上使用特殊字体ui的设计网站
  • 教做视频的网站搜索引擎及门户网站介绍总结
  • 英文介绍做美食视频网站工服专业制作
  • 网站建设app开发合同范本怎么做微信点击网站打赏看片
  • 如何制作app网站中国建工网校官网
  • 金溪网站建设推广辽宁网站建设价格
  • 深圳做手机网站设计网站开发后台数据怎么来
  • 上传自己做的网站后台怎么办婚纱摄影网站开发
  • 深度网营销型网站建设上海东方网首页
  • 名律汇网站建设设计创意ppt模板大全
  • 网站 公司 备案广州建设信息网官方网站
  • 南通免费网站建设站长工具国产
  • 解析网站怎么做百度推广方案
  • 深圳专业营销网站公司上海迈诺网站建设
  • 河北网站建设电话无为网站建设
  • 重庆新闻经典论坛seo如何优化排名
  • 网站代理备案价格北京网站建设付款方式
  • 速效成交型网站中国建设银行官方网站纪念钞预约
  • 网站开发验收流程图云主机和云服务器有什么区别