python爬取相关网站一些信息-创新互联
import requests
from bs4 import BeautifulSoup
def getpage(url):
responce = requests.get(url)
soup = BeautifulSoup(responce.text,'lxml')
return soup
def getlinks(link_url):
responce = requests.get(link_url)
format_list = BeautifulSoup(responce.text,'lxml')
link_div = format_list.find_all('div',class_='pic-panel')
links = [div.a.get('href') for div in link_div]
return links
url = 'https://bj.lianjia.com/zufang/'
house_url = 'https://bj.lianjia.com/zufang/101102926709.html'
def get_house_info(house_url):
# li = getlinks(url)
# print(li)
soup = getpage(house_url)
prince = soup.find('span',class_='total').text
unit = soup.find('span',class_='unit').text.strip()
house_info = soup.find_all('p')
area = house_info[0].text[3:]
layout = house_info[1].text[5:]
floor = house_info[2].text[3:]
direction = house_info[3].text[5:]
location = house_info[4].text[3:]
xiaoqu_location = house_info[5].text[3:7]
create_time = house_info[6].text[3:]
info ={'面积':area,
'分布':layout,
'楼层':floor,
'方向':direction,
'价格':prince,
'单价':unit,
'地铁':location,
'小区':xiaoqu_location,
'时间':create_time
}
return info
house = get_house_info(house_url)
for k,v in house.items():
print('{}:{}'.format(k,v))
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
成都创新互联-专业网站定制、快速模板网站建设、高性价比乌审网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式乌审网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖乌审地区。费用合理售后完善,10多年实体公司更值得信赖。本文标题:python爬取相关网站一些信息-创新互联
网站路径:http://lswzjz.com/article/coegdo.html