レジストリデータ2

1808 ワード

#coding:utf-8
import sys
reload(sys)
sys.setdefaultencoding("utf-8")  # 。 , pandas DataFrame 
import pandas as pd
import urllib2
import urllib
import time
import re
from bs4 import BeautifulSoup

# 
myurl="http://hz.lianjia.com/ershoufang/pg"+str(1)
req = urllib2.Request(myurl)
myResponse = urllib2.urlopen(req)
myPage = myResponse.read()
unmyPage = myPage.decode('utf-8') # Unicode 

# 
c1=re.findall('(.*?)(.*?)
',unmyPage,re.S)
totalPrice=[]
for item in c1:
newitem=item[0]+item[1]
newitem=str(newitem)
totalPrice.append(newitem)
#ルームソース情報の照合
c2=re.findall('data-el="region">(.*?)',unmyPage,re.S)
houseinfo=[]
for item in c2:
#item=item.encode('utf-8')
#print isinstance(item,str)
houseinfo.append(item)
#部屋の注目度と一致する
c3=re.findall('(.*?)',unmyPage,re.S)
followinfo=[]
for item in c3:
followinfo.append(item)
house=pd.DataFrame({'totalprice':totalPrice,'houseinfo':houseinfo,
'followinfo':followinfo})
print type(house['totalprice'][0]) #str
print type(house['houseinfo'][0]) #unicode
print type(house['followinfo'][0]) #unicode
print house.head()
2、運行結果:
G:\python2.7\python.exe E:/python37/jiebacut_01/DateCrawler/lianjia/lianjia2.py



                   followinfo    ...     totalprice
0   173  /  58  / 3     ...           950 
1   238  /  33  / 6     ...           480 
2   164  /  19  / 3     ...           270 
3  156  /  11  / 11     ...           585 
4    70  /  26  / 3     ...           250 

[5 rows x 3 columns]

Process finished with exit code 0