python 爬香港591房源 https://rent.591.com.hk/
来源:互联网 发布:航空大亨4无法连接网络 编辑:程序博客网 时间:2024/04/30 22:34
# -*- coding: utf-8 -*-"""author:Ane"""import sysfrom bs4 import BeautifulSoupimport requestsimport jsonimport timeimport MySQLdbreload(sys)sys.setdefaultencoding("utf-8")def dealDate(url): header = { "Host":"rent.591.com.hk", "User-Agent":"Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0", "Accept":"application/json, text/javascript, */*; q=0.01", "Accept-Language":"zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3", "Accept-Encoding":"gzip, deflate, br", "Referer":"https://rent.591.com.hk/", "X-Requested-With":"XMLHttpRequest", "Cookie":"think_language=zh-hk; think_template=default; PHPSESSID=nc8mgk24fa4qo1hu4f2ut2v1l5; __asc=cefa42e715b83db8b19bd2da4b9; __auc=cefa42e715b83db8b19bd2da4b9; _ga=GA1.3.834050676.1492565855; _gat=1; _gat_rent=1", "Connection":"keep-alive" } web_date = requests.get(url,headers = header) dates = json.loads(web_date.text) db = MySQLdb.connect("localhost", "root", "mysqlmima", "rentdate",charset = "utf8") cursor = db.cursor() #获取数据库游标 for date in dates["items"]: price = date["price"].strip() address = date["address"].strip() area = date["area"].strip() linkman = date["linkman"].strip() img = date["cover_img"].strip() #print price, address, area, linkman, img sql = """INSERT INTO biao_rentdate (ADDRESS, AREA, LINKMAN, PRICE, IMG) VALUES ('%s', '%s', '%s', '%s', '%s')"""%(address,area,linkman,price,img) #数据库添加语句 try: cursor.execute(sql) db.commit() except: db.rollback() db.close()def start(): urls = ['https://rent.591.com.hk/?m=home&c=search&a=rslist&v=new&type=1&hasimg=1&searchtype=1&p={0}'.format(str(i)) for i in range(1,175)] for url in urls: dealDate(url)start()
没啥难度,只是用到了数据库 做个笔记 以防以后查看
0 0
- python 爬香港591房源 https://rent.591.com.hk/
- 强制Google.com.hk域名使用https
- 周一起,谷歌中国关闭,转至香港google.com.hk
- 如何避免打开谷歌自动跳转到香港GOOGLE.COM.HK?
- 利用python爬取我爱我家租赁房源信息
- Python爬虫1----房源信息
- 房源
- 香港 (HK) The New iPad 价格。
- laokedao.com批量导入房源接口规范
- 香港胎儿性别鉴定/hk验血测性别
- Google.com.hk-关闭搜索过滤
- Google.com.hk时常进不了
- 访问google.com而不是google.hk
- http://www.google.com.hk/patents/US8566217
- 近期google.com.hk无法访问的解决方法
- 诸葛找房房源信息爬取
- Use google.com instead of google.com.hk
- 解决google.com自动跳转到google.com.hk问题
- 安卓WebView使用总结
- splunk的通用forwarder 配置问题
- Cygwin编译遇到的那些坑
- [源码]Concurrent包之信号量
- 【笔记】数据挖掘导论(持续更新)
- python 爬香港591房源 https://rent.591.com.hk/
- 设置imageView顶部两个圆角
- 如何把Excel坐标加载到谷歌卫星地图上
- Combining policy gradient and Q-learning
- LR_中央控制器、负载生成器
- Cookie与Session的区别-总结很好的文章
- 2016 学习笔记(二)
- 郑轻校赛 A题 点到线段距离 By Assassin
- VS2015快捷键大全