import requests
import urllib.parse
import datetime
from lxml import etree fhout = open("result.txt", 'a') baseurl = 'https://zh.wikipedia.org/wiki/' begin_date = datetime.datetime.strptime('2016-01-01', "%Y-%m-%d")
contents=[]
for i in range(196,366):
content = []
mid_date = begin_date + datetime.timedelta(days=i)
thedate = str(mid_date.month) + '月' + str(mid_date.day) + '日'
print(thedate)
urlthedate = urllib.parse.quote(thedate)
url = baseurl + urlthedate
print(url)
html = requests.get(url).text.encode("utf-8") tree = etree.HTML(html)
ul = tree.xpath('//li[@class="toclevel-1 tocsection-1"]/ul/li/a/span[@class="toctext"]/text()')
num = len(ul)
fhout.write("data_"+str(mid_date.month)+"_"+str(mid_date.day)+"=[")
for i in range(num, 0, -1):
records = tree.xpath('//div[@id="mw-content-text"]/div[@class="mw-parser-output"]/ul['+ str(i) +']/li[descendant-or-self::text()]')
ulen = len(records)
for j in range(ulen-1,-1,-1):
content.append(records[j].xpath('string(.)'))
fhout.write("'"+records[j].xpath('string(.)')+"'\n")
fhout.write("]\n")
print(content)
contents.append(content) fhout.close()

python+xpath+requests爬取维基百科历史上的今天的更多相关文章

  1. 从0开始学爬虫8使用requests/pymysql和beautifulsoup4爬取维基百科词条链接并存入数据库

    从0开始学爬虫8使用requests和beautifulsoup4爬取维基百科词条链接并存入数据库 Python使用requests和beautifulsoup4爬取维基百科词条链接并存入数据库 参考 ...

  2. python+selenium+requests爬取我的博客粉丝的名称

    爬取目标 1.本次代码是在python2上运行通过的,python3的最需改2行代码,用到其它python模块 selenium 2.53.6 +firefox 44 BeautifulSoup re ...

  3. python+selenium+requests爬取qq空间相册时遇到的问题及解决思路

    最近研究了下用python爬取qq空间相册的问题,遇到的问题及解决思路如下: 1.qq空间相册的访问需要qq登录并且需是好友,requests模块模拟qq登录略显麻烦,所以采用selenium的dri ...

  4. python简单爬虫爬取百度百科python词条网页

    目标分析:目标:百度百科python词条相关词条网页 - 标题和简介 入口页:https://baike.baidu.com/item/Python/407313 URL格式: - 词条页面URL:/ ...

  5. Python使用requests爬取一个网页并保存

    #导入 requests模块import requests #设置请求头,让网站监测是浏览器 headers = { 'user-agent': 'Mozilla/5.0 (Windows NT 6. ...

  6. 爬取维基百科人物介绍,并使用pymysql存储到数据库

    代码如下: from urllib.request import urlopen from bs4 import BeautifulSoup import re import datetime imp ...

  7. Python转页爬取某铝业网站上的数据

    天行健,君子以自强不息:地势坤,君子以厚德载物! 好了废话不多说,正式进入主题,前段时间应朋友的请求,爬取了某铝业网站上的数据.刚开始呢,还是挺不愿意的(主要是自己没有完整的爬取过网上的数据哎,即是不 ...

  8. jQuery请求维基百科[历史上的今天]

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. python xpath图片爬取

    import requests from urllib.request import urlretrieve from lxml import etree headers = { 'User-Agen ...

随机推荐

  1. nginx高性能webserver具体解释(1)--安装nginx

    1. 下载 本次使用nginx-0.1.2.3 版本号,下载地址 http://nginx.org/en/download.html  新公布版本号 http://nginx.org/download ...

  2. 媒体类型(MIME类型)

    # encoding=utf-8 #python 2.7.10 #xiaodeng #HTTP权威指南 #HTTP协议:超文本传输协议是在万维网上进行通信时所使用的协议方案. #媒体类型: #HTTP ...

  3. rabbitmq vhost

    参考 http://blog.163.com/sky20081816@126/blog/static/16476102320107173226920/ http://blog.csdn.net/kev ...

  4. Cocos2dx 学习记录 [2] 关于混合和高亮一些知识点的体会

    网上有一篇博客讲的是高亮的http://www.cnblogs.com/mrblue/p/3455775.html 就是这篇,尽管代码简单,但对于刚開始学习的人的我,看的还是有些吃力的,毕竟有些内容不 ...

  5. 转载【微信小程序】:微信小程序滚动Tab选项卡:左右可滑动切换(仿某宝)

    1.本文转载至:http://blog.csdn.net/sophie_u/article/details/71745125 2.效果: 3.最终效果如上.问题: 1).tab标题总共8个,所以一屏无 ...

  6. setting.xml配置详解

    http://blog.csdn.net/uohzoaix/article/details/7035302 http://www.micmiu.com/software/build/maven-set ...

  7. http://www.cnblogs.com/txw1958/p/alipay-f2fpay.html

    一.条码支付及二维码支付介绍 1. 条码支付 条码支付是支付宝给到线下传统行业的一种收款方式.商家使用扫码枪等条码识别设备扫描用户支付宝钱包上的条码/二维码,完成收款.用户仅需出示付款码,所有收款操作 ...

  8. Linux-Tmux使用初体验

    Tmux使用初体验 tmux #开启tmux tmux ls #显示已有tmux列表(ctrl+b s) tmux attach-session -t 数字 #选择tmux ctrl+b c 创建一个 ...

  9. 关于JavaScript中Get/Set访问器

    有时候大家可能会纳闷,在使用JavaScript的时候,只需要给一个系统变量赋值就可以触发一系列操作去相应. 但是我们在写Js的时候,修改了一个自定义变量,却连个P都没有.是不是很郁闷呢? 其实,我们 ...

  10. Quartz2之入门示例

    环境:XP+Myeclipse6.5+JDK1.6 quartz官网:http://www.quartz-scheduler.org/ 参考资料 1 Quartz任务调度快速入门 http://www ...