python爬虫之根据手机号码获取卡号归属地

需求与目的

根据手机号码查询号码归属地,了解Python的爬取资料还是很容易。全部代码如下就可以返回需要的数据了。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Randy'
from bs4 import BeautifulSoup
import requests

html_doc = requests.get('http://www.ip138.com:8080/search.asp?action=mobile&mobile=13800138000')
soup = BeautifulSoup(html_doc.content,'lxml')
mark = soup.find_all('td',class_="tdc2")
print '手机号码:',mark[0].get_text()
print '卡号归属地:',mark[1].get_text()

输出

手机号码: 13800138000 测吉凶(新)
卡号归属地: 北京

需要的库

  1. requests

    Python 最好用的第三方 http 库-Requests.

    Requests安装

    pip install requests
    
  2. BeautifulSoup

    Python 最好用的第三方分析HTML代码的库。

    BeautifulSoup安装

    pip install beautifulsoup4
    


评论(0条)

暂时还没有评论,第一个来评论吧!


我要发表看法

引用   粗体   链接   缩进  

最近编辑

热门标签