1211完成58手机号进mongo

2016-12-11  本文已影响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)





'''
上一篇下一篇

猜你喜欢

热点阅读