美文网首页
1211完成58手机号进mongo

1211完成58手机号进mongo

作者: 木马音响积木 | 来源:发表于2016-12-11 11:25 被阅读0次

总结:手机号先小搞几个。

结果;图片

11233.PNG 4545464.PNG

代码

#!C:\Python35\python.exe
# coding=utf-8

import requests
from bs4 import BeautifulSoup
import urllib.request
import time
import pymongo
from pymongo import MongoClient
import lxml

client =MongoClient('localhost',27017)
db=client['shoujila']
shoujinum = db['shoujinum']

def insert_shoujihao_info(url):
    web_data=requests.get(url)
    soup =BeautifulSoup(web_data.text,'lxml')
    shoujihaos = soup.select('strong.number')
    for shoujihao in shoujihaos:
        info = {'shoujihao': shoujihao.get_text()}
        print(info)
        shoujinum.insert_one(info)

def find_shoujihao():
    for info in shoujinum.find():
        #if info['price']>=405:
        print(info)
        print("finish!")

urls=['http://bj.58.com/shoujihao/pn{}/'.format(number) for number in range(1,20)]
for one_url in urls:
    insert_shoujihao_info(one_url)

find_shoujihao()
'''
web_data = requests.get(url)
soup = BeautifulSoup(web_data.text, 'lxml')
#print(soup)
shoujihaos=soup.select('strong.number')
#print(shoujihaos)

http://bj.58.com/shoujihao/pn7/
for shoujihao in shoujihaos:
    info = {
        'shoujihao': shoujihao.get_text()
    }
    print(info)
    shoujinum.insert_one(info)





'''

相关文章

网友评论

      本文标题:1211完成58手机号进mongo

      本文链接:https://www.haomeiwen.com/subject/iifpmttx.html