博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
最近要租房子,用Python看一下房源吧..
阅读量:7240 次
发布时间:2019-06-29

本文共 2523 字,大约阅读时间需要 8 分钟。

前言:最近我的朋友想要租房子,为了装个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 requestsfrom bs4 import BeautifulSoupimport 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 = 0while(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='198876', 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)# 提交SQLconnection.commit()

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

转载于:https://www.cnblogs.com/ZaraNet/p/9774071.html

你可能感兴趣的文章
python学习笔记4-python文件操作
查看>>
Python WEB开发环境搭建及配置六之Django
查看>>
Ubuntu14.04安装vim
查看>>
我的友情链接
查看>>
Juniper防火墙部署工程
查看>>
使ActionBar(Toolbar)的Up导航和实体按键Back实现同步
查看>>
umask命令
查看>>
在XenServer 6.0中设置自动启动虚拟机
查看>>
Java并发编程:线程间协作的两种方式:wait、notify、notifyAll和Conditio
查看>>
mysql 引擎介绍
查看>>
解决Struts2 与 hibernate 中 javassist 冲突问题
查看>>
对一个C语言小程序的剖析
查看>>
网络服务之dhcp
查看>>
Linux基于PXE实现系统全自动无人值守安装
查看>>
我的友情链接
查看>>
Soap和REST
查看>>
数据结构中各种排序的思路
查看>>
配置服务主机名和域名IP解析
查看>>
5种I/O模型
查看>>
3月23日作业
查看>>