前言:最近我的朋友想要租房子,为了装个b,决定运用技术去帮助他。

这个网站是什么我也不知道 反正是一个房子交易网站  http://www.ljia.net/

设置请求头

headers = {'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.8',
'Cache-Control': 'max-age=0',
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'Connection': 'keep-alive',
'Referer': 'http://www.baidu.com/'
}

代码:

import requests
from bs4 import BeautifulSoup
import re; headers = {'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.8',
'Cache-Control': 'max-age=43200',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36',
'Connection': 'keep-alive',
'Referer': 'no-referrer-when-downgrade'
} def get_Detail_List(pageindex):
url = "http://www.ljia.net/zf/p-"+str(pageindex)+'.html'
response = requests.get(url)
soup = BeautifulSoup(response.text,'html.parser')
resultTitle = soup.find_all('h2',{'class','title'})
for i in resultTitle:
urler = 'http://www.ljia.net'+i.a['href']
response = requests.get(urler)
souper = BeautifulSoup(response.content)
content = souper.select('div #lpname div[class=floatl]')
dj = BeautifulSoup(str(content))
money = souper.find_all('div',{'class','trl-item'})
moneybs = BeautifulSoup(str(money))
xinxiList = souper.find_all('div',{'class','tt'})
xinxi = BeautifulSoup(str(xinxiList))
consolestr = dj.get_text().replace('[','').replace(']','').strip()+moneybs.get_text().replace('[','').replace(']','').strip()+xinxi.get_text().replace('[','').replace(']','').strip()
print(consolestr.strip().replace(' ', '').replace('\n', '').replace('\t', '').replace('\r', '').strip()) count = 0
while(count<100):
get_Detail_List(count)
count = count+1

哈哈就是这么简单,让我们看下效果图吧!!!

然后,你可以把这些数据放到Mysql,Redis 那我可管不着 都可以的了

import pymysql.cursors

# 连接MySQL数据库
connection = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='', db='guest',
charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor) # 通过cursor创建游标
cursor = connection.cursor() # 创建sql 语句,并执行
sql = "INSERT INTO `users` (`email`, `password`) VALUES ('huzhiheng@itest.info', '123456')"
cursor.execute(sql) # 提交SQL
connection.commit()

回头在搞个图形  !! 睡觉!

最近要租房子,用Python看一下房源吧..的更多相关文章

  1. 11月6日上午PHP练习《租房子》解析

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  2. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  3. PHP实例练习--投票和租房子

    一,调查问卷 效果图:

  4. php 租房子(练习题)

    一.题目要求 1.功能描述   出租房屋数据管理及搜索页面 2.具体要求 (1) 创建数据库HouseDB,创建表House,要求如下: 二.题目做法 1.建立数据库 2.封装类文件 <?php ...

  5. php封装+租房子练习题

    第一个页面DBDA.class.php <?php class DBDA { public $host = "localhost"; public $uid = " ...

  6. php练习 租房子

    题目要求 1.封装类 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 public $yonghuming=&q ...

  7. PHP 练习(租房子)

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  8. PHP 练习3:租房子

    一.题目要求 二.题目做法 1.建立数据库 2.封装类文件 <?php class DBDA { public $fuwuqi="localhost"; //服务器地址 pu ...

  9. 快速入门python看过的一些资料

    我快速入门python看过的一些资料 B站的视频 10天自学Python,轻松掌握Python基础[千锋] 廖雪峰 - Python教程 https://www.liaoxuefeng.com/wik ...

随机推荐

  1. 关于<软件>的定义

    百度百科: 软件是一系列按照特定顺序组织的计算机数据和指令的集合.一般来讲软件被划分为系统软件.应用软件和介于这两者之间的中间件. 国标中的定义: 与计算机系统操作有关的计算机程序.规程.规则,以及可 ...

  2. Tomcat映射路径

    打开tomcat安装包,在config目录下修改server.xml文件: 在<Host>标签中添加: <Context path="" docBase=&quo ...

  3. docker-compose模板文件参数说明

    working_dir:一般这个参数用在应用程序Services下,我们指定应用程序所在的目录为当前目录,类似linux中的cd working_dir.其余的参数,例如command等就是基于此参数 ...

  4. 英语知识积累-D01-body+animal

    My body What's your name? Here are lots of children playing. Are they happy or sad? Who's waving at ...

  5. Centos 7安装python3(PY3.6)

    # 安装 sudo yum install centos-release-scl sudo yum install rh-python36 #开启 scl enable rh-python36 bas ...

  6. python 迭代器,生成器

    在 python 中我们常用 for in 来遍历 list, set, dict, str 等. for in 的本质就干了两件事: 调用 __iter__() 获取迭代器; 调用 next() 直 ...

  7. C#找不到ConfigurationManager类

    c#添加了Configuration;后,竟然找不到 ConfigurationManager 这个类,后来才发现:虽然引用了using System.Configuration;这个包,但是还是不行 ...

  8. 马昕璐 201771010118《面向对象程序设计(java)》第十八周学习总结

    实验十八  总复习 实验时间 2018-12-30 1.实验目的与要求 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设 ...

  9. group by 多个字段

    众所周知,group by 一个字段是根据这个字段进行分组,那么group by 多个字段的结果是什么呢?由前面的结论类比可以得到,group by 后跟多个子段就是根据多个字段进行分组 注:下面的例 ...

  10. DRC错误解决办法

    一.WARNING(ORCAP-1589): Net has two or more aliases - possible short? 错误原因:一个网络有两个网络标号,可能造成短路! 问题本质:原 ...