练习场景:在某一个网页上有些字段是我们感兴趣的,我们希望摘取出来,进行其他操作。但是这些字段可能在一个网页的不同地方。例如,我们需要在关于平安页面-联系我们,摘取电话号码。

思路拆分:
1. 首先,需要得到当前页面的source内容,就像,打开一个页面,右键-查看页面源代码。
在Selenium中有driver.page_source
2. 找出规律,通过正则表达式去摘取匹配的字段,存储到一个字典或者列表。
Python中利用正则,需要导入re模块
https://blog.csdn.net/m0_37852369/article/details/78829174
3. 循环打印字典或列表中内容,Python中用 for 语句实现。
print mobile

运行结果:

网友评论