python爬虫——正则爬取手机号

Python013

python爬虫——正则爬取手机号,第1张

cmd → pip install re → 回车

cmd → pip install requests → 回车

cmd → pip install beautifulsoup4 → 回车

import requests

import re

from bs4 import BeautifulSoup

r = requests.get("http://www.haomahao.com/")

parttern = "1[35789]\d{9}"

import requests

import re

from bs4 import BeautifulSoup

def down():

    r = requests.get("http://www.haomahao.com/") #调用网页

    r.encoding = r.apparent_encoding #更改网页编码,防止出现乱码

    #print(r.text)

    bs = BeautifulSoup(r.text,"html.parser")

    str1 = bs.getText() #将BeautifulSoup提出出来的写完text

    parttern = "1[35789]\d{9}" #编写手机号正则表达式

    list = re.findall(parttern,str1)

    #print(list) #调试正则是否正确

    f = open("手机号.txt",mode="w",encoding="utf-8") #写入文件

    f.write("\n".join(list))

    f.close()

if __name__ == "__main__":

    down()

python无法通过手机号码和姓名,来开启对方手机摄像头。根据查询相关资料可知,python是一种编程语言,作用是面向对象编程,可以通过python进行数据分析、数据爬取、深度学习框架搭建和算法编写,无法完成通过手机号码和姓名,来开启对方手机摄像头的功能。