要求:
爬取网页你好,蜘蛛侠!中的Python之禅中英文版本,并且打印。
 
目的:
练习使用selenium爬取动态网页的信息。
练习selenium与BeautifulSoup的搭配使用。
 
 
 
方法一: 用selenium
 
 from selenium import webdriver
import time driver = webdriver.Chrome() driver.get('https://localprod.pandateacher.com/python-manuscript/hello-spiderman/')
time.sleep(2) button = driver.find_element_by_class_name('sub')
button.click()
time.sleep(1) python_zens = driver.find_elements_by_class_name('content') for python_zen in python_zens:
print(python_zen.find_element_by_tag_name('h1').text,end='\n\n')
print(python_zen.find_element_by_tag_name('p').text,end='\n\n') driver.close()
 The Zen of Python

 Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those! Python之禅 优美胜于丑陋
明了胜于晦涩
简洁胜于复杂
复杂胜于凌乱
扁平胜于嵌套
间隔胜于紧凑
可读性很重要
即便假借特例的实用性之名,也不可违背这些规则
不要包容所有错误,除非你确定需要这样做
当存在多种可能,不要尝试去猜测
而是尽量找一种,最好是唯一一种明显的解决方案
虽然这并不容易,因为你不是 Python 之父
做也许好过不做,但不假思索就动手还不如不做
如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然
命名空间是一种绝妙的理念,我们应当多加利用
 
方法二:用selenium 和 BeautifulSoup
 
 from selenium import webdriver
from bs4 import BeautifulSoup
import time driver = webdriver.Chrome() driver.get('https://localprod.pandateacher.com/python-manuscript/hello-spiderman/')
time.sleep(2) button = driver.find_element_by_class_name('sub')
button.click()
time.sleep(1) pagesource = driver.page_source soup = BeautifulSoup(pagesource,'html.parser')
items = soup.find_all(class_='content')
for item in items:
print('\n\t'+item.find('h1').text)
print(item.find('p').text) driver.close()
         The Zen of Python

             Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those! Python之禅 优美胜于丑陋
明了胜于晦涩
简洁胜于复杂
复杂胜于凌乱
扁平胜于嵌套
间隔胜于紧凑
可读性很重要
即便假借特例的实用性之名,也不可违背这些规则
不要包容所有错误,除非你确定需要这样做
当存在多种可能,不要尝试去猜测
而是尽量找一种,最好是唯一一种明显的解决方案
虽然这并不容易,因为你不是 Python 之父
做也许好过不做,但不假思索就动手还不如不做
如果你无法向人描述你的方案,那肯定不是一个好方案;反之亦然
命名空间是一种绝妙的理念,我们应当多加利用

25、Python之禅的更多相关文章

  1. python 之禅

    想要真正深入了解一门语言,需要用心去感受.下面是python之禅,python的设计哲学,对于编程很有指导意义.(翻译部分摘自网络,同时自己有一些更改) >>> import thi ...

  2. Python的禅,“提姆彼得斯”说的非常有道理道出了这门编程语言的真谛!

    The Zen of Python, by Tim Peters Beautiful is better than ugly.Explicit is better than implicit.Simp ...

  3. Python之禅+八荣八耻

    Python之禅 (The Zen of Python):是Python语言的指导原则,可以在Python命令行输入import this显示. import this >>> Th ...

  4. Python之禅及释义

    在python shell中敲 import this会触发一个彩蛋,神奇的打印下面一段话: The Zen of Python, 即python之禅, 1999年Tim Peters大牛总结的&qu ...

  5. Python之禅及其翻译

    凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分 ...

  6. Python自学:第二章 Python之禅

    >>print import <Python之禅>,提姆·彼得斯著 美胜于丑. 显式优于隐式. 简单胜于复杂. 复杂总比复杂好. 平的比嵌套的好. 稀疏胜于稠密. 可读性计数. ...

  7. Python之禅的翻译和解释

      The Zen of Python, by Tim Peters   Beautiful is better than ugly. Explicit is better than implicit ...

  8. Python学习手册之 Python 之禅、Python 编程规范和函数参数

    在上一篇文章中,我们介绍了 Python 的正则表达式使用示例,现在我们介绍 Python 之禅. Python 编程规范和函数参数.查看上一篇文章请点击:https://www.cnblogs.co ...

  9. (转)python之禅

    凡是用过 Python的人,基本上都知道在交互式解释器中输入 import this 就会显示 Tim Peters 的 The Zen of Python,但它那偈语般的语句有点令人费解,所以我想分 ...

随机推荐

  1. Unity3D_(游戏)2D坦克大战 像素版

    2D坦克大战    像素版 游戏规则: 玩家通过上.下.左.右移动坦克,空格键发射子弹 敌人AI出身时朝向己方大本营(未防止游戏快速结束,心脏上方三个单位障碍物设为刚体) 当玩家被击杀次数>=3 ...

  2. maven jdbc 驱动安装

    https://mvnrepository.com/ 搜索  : com.microsoft.sqlserver 点击进入: https://mvnrepository.com/artifact/co ...

  3. 有关ajax中的URL问题

    url  :  ../../Service/MSD_Maintain.ashx/?action=Add4T2 url  :  Handler/MaintainHandler.ashx/?action= ...

  4. Java-线程等待、唤醒与中断

    一.sleep() 与 wait() 两者都会让当前线程进入等待状态.唤醒后都需要等待 CPU 资源,不一定会立即执行.若在等待期间被调用此线程的的 interrupt() 方法,将会产生 Inter ...

  5. 怎样用 Bash 编程:逻辑操作符和 shell 扩展

    学习逻辑操作符和 shell 扩展,本文是三篇 Bash 编程系列的第二篇. Bash 是一种强大的编程语言,完美契合命令行和 shell 脚本.本系列(三篇文章,基于我的 三集 Linux 自学课程 ...

  6. 在RHEL6_Oracle_Linux_6上生成正确的udev_rule_规则文件

    1. #首先确认是 Linux 6.0以上版本 [root@vrh6 dev]# cat /etc/issue          Oracle Linux Server release 6.2Kern ...

  7. Oracle Rac 测试

      #还是使用之前的脚步来进行测试 #Author : Kconnie Pong Oracle@PONGDB:~> more load_balance.sh #!/bin/bash ..} do ...

  8. Git-Runoob:Git 服务器搭建

    ylbtech-Git-Runoob:Git 服务器搭建 1.返回顶部 1. Git 服务器搭建 上一章节中我们远程仓库使用了 Github,Github 公开的项目是免费的,但是如果你不想让其他人看 ...

  9. IFB上挂载NETEM

    转发虚拟网卡的ingress 建立虚拟网卡的ingress转发到ifb0(每一个Pod): tc qdisc add dev calixxxxxxxxxxx ingress tc filter add ...

  10. surface book2 添加自定义分辨率

    surface book2 13.5英寸  是3:2的屏幕, 因为默认分辨率3000*2000实在是太高了,看字的时候眼睛有点吃不消  即使开启windows的自定义缩放也有点难受,加上windows ...