本文主要是介绍Scrapy58同城租房房屋信息(完整),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Scrapy
- 创建Scrapy项目
-
scrapy startproject mySpider
-
- 生成一个爬虫
-
scrapy genspider 爬虫名字 "允许爬取网址范围"
-
- 运行爬虫
-
scrapy crawl 爬虫名字
-
Xpath语法提取元素
小编相信你们都会的,在此就放上一个官方文档,有需要便可查看
- Xpath教程
58同城字体加密
- 破解字体加密,一般是先找到字体文件,下载到本地,获取字体的映射关系解析真正的数字
在页面中我们可以通过查看源码看到该字体是通过base64加密之后放到js里面的
- 按Ctrl + f 搜索base64即可看到
要想获取该字体文件,我们应该吧加密部分给取出来,用到正则很容易给取出
- 下面是我的代码
# 这里我是先取出所有js代码 再通过正则匹配出想要的字符
# 如果你们有其他方法更好script_js = response.xpath('/html/head/script').extract_first()
# print("base64_js代码",script_js)result = re.search(r"base64.*format", script_js)b_s = result.group()# 这是最后得到的base64码字符
base64_str = b_s[7:-9]
# 类似于这样的字符:
"""
AAEAAAALAIAAAwAwR1NVQiCLJXoAAAE4AAAAVE9TLzL4XQjtAAABjAAAAFZjbWFwq8R/YwAAAhAAAAIuZ2x5ZuWIN0cAAARYAAADdGhlYWQaGmlZAAAA4AAAADZoaGVhCtADIwAAALwAAAAkaG10eC7qAAAAAAHkAAAALGxvY2ED7gSyAAAEQAAAABhtYXhwARgANgAAARgAAAAgbmFtZTd6VP8AAAfMAAACanBvc3QEQwahAAAKOAAAAEUAAQAABmb+ZgAABLEAAAAABGgAAQAAAAAAAAAAAAAAAAAAAAsAAQAAAAEAAOCqxe5fDzz1AAsIAAAAAADbSY8kAAAAANtJjyQAAP/mBGgGLgAAAAgAAgAAAAAAAAABAAAACwAqAAMAAAAAAAIAAAAKAAoAAAD/AAAAAAAAAAEAAAAKADAAPgACREZMVAAObGF0bgAaAAQAAAAAAAAAAQAAAAQAAAAAAAAAAQAAAAFsaWdhAAgAAAABAAAAAQAEAAQAAAABAAgAAQAGAAAAA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wABAAAAAAADAA8AFgABAAAAAAAEAA8AJQABAAAAAAAFAAsANAABAAAAAAAGAA8APwABAAAAAAAKACsATgABAAAAAAALABMAeQADAAEECQABAB4AjAADAAEECQACAA4AqgADAAEECQADAB4AuAADAAEECQAEAB4A1gADAAEECQAFABYA9AADAAEECQAGAB4BCgADAAEECQAKAFYBKAADAAEECQALACYBfmZhbmdjaGFuLXNlY3JldFJlZ3VsYXJmYW5nY2hhbi1zZWNyZXRmYW5nY2hhbi1zZWNyZXRWZXJzaW9uIDEuMGZhbmdjaGFuLXNlY3JldEdlbmVyYXRlZCBieSBzdmcydHRmIGZyb20gRm9udGVsbG8gcHJvamVjdC5odHRwOi8vZm9udGVsbG8uY29tAGYAYQBuAGcAYwBoAGEAbgAtAHMAZQBjAHIAZQB0AFIAZQBnAHUAbABhAHIAZgBhAG4AZwBjAGgAYQBuAC0AcwBlAGMAcgBlAHQAZgBhAG4AZwBjAGgAYQBuAC0AcwBlAGMAcgBlAHQAVgBlAHIAcwBpAG8AbgAgADEALgAwAGYAYQBuAGcAYwBoAGEAbgAtAHMAZQBjAHIAZQB0AEcAZQBuAGUAcgBhAHQAZQBkACAAYgB5ACAAcwB2AGcAMgB0AHQAZgAgAGYAcgBvAG0AIABGAG8AbgB0AGUAbABsAG8AIABwAHIAbwBqAGUAYwB0AC4AaAB0AHQAcAA6AC8ALwBmAG8AbgB0AGUAbABsAG8ALgBjAG8AbQAAAAIAAAAAAAD/EwB3AAAAAAAAAAAAAAAAAAAAAAAAAAAACwECAQMBBAEFAQYBBwEIAQkBCgELAQwAAAAAAAAAAAAAAAAAAAAA
"""
我们取出加密的字体字符后,还需要获取通过他加密的字符,也就是
- 这个我们只需要通过xpath语法就可获取到
接下来就到了找对应关系进行解密的时候了,下面是代码
import base64
import iofrom fontTools.ttLib import TTFontdef covert_secret_int(house_str_one, base64_str):# base64解析 转换成二进制形式 下载到本地ttf文件ttf = base64.decodebytes(base64_str.encode())ZufangFont = TTFont(io.BytesIO(ttf))ZufangFont.save('58Fang.ttf')# 使用fontTools工具 获取对应关系ZufangFont.saveXML('58Fang.xml')uniList = ZufangFont['cmap'].tables[0].ttFont.getGlyphOrder()uniListkey = ZufangFont['cmap'].tables
这篇关于Scrapy58同城租房房屋信息(完整)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!