python爬取w3cschool python练习实例100例
2017-02-27 19:44
423 查看
w3cschool python练习实例100例
![](https://img-blog.csdn.net/20170227194313217?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvSkhUU3Vuc2hpbmU=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
代码如下:
代码如下:
# -*- coding: utf-8 -*- import requests from bs4 import BeautifulSoup #content > p:nth-child(3) > strong for page in range(1,101,1): url = "http://www.w3cschool.cn/python/python-exercise-example{}.html".format(page) data = requests.get(url).text soup = BeautifulSoup(data,"lxml") titles = soup.find_all(id="content") f = open("test1.txt",'a') for n in titles: title = n.get_text() print(title,file =f) f.close()
相关文章推荐
- Python基础教程100例 练习1
- 菜鸟教程 Python100例 之实例29
- Python 练习实例20
- Python 练习实例25
- Python 练习实例24
- C语言学习100例实例程序--我练习的C++版(每天一题夯实基础)
- Python 练习实例29
- Python 练习实例14
- Python 练习实例13
- Python 练习实例27
- Python 练习实例1
- Python 练习实例6
- Python 练习实例5
- Python 练习实例15
- Python 练习实例10
- Python基础教程100例 练习2
- Python 练习实例4
- Python 练习实例8
- Python 练习实例17
- Python 练习实例28