淘宝密码(爬虫爬取淘宝美食的数据源码)

淘宝密码(爬虫爬取淘宝美食的数据源码)

正则匹配找规律


import re

import requests

# 在搜索框中输入美食得到的数据q=%E7%BE%8E%E9%A3%9F
url = 'https://s.taobao.com/search?q=%E7%BE%8E%E9%A3%9F'
response = requests.get(url)
# print(response.text)

# 用正则对html源码进行解析到一个json数据
pattern = re.compile('g_page_config =(.*?);', re.S)
result = re.search(pattern, response.text)
# print(result.group(1))

# 发现并不是那么简单而是加密的数据并是有规律可寻的,以下是加密的几个数据段
json_data = re.sub('(\\\\u003d)|(\\\\u0026)|(\\\\u003c)|(\\\\u003e)', '', result.group(1))
posted @ 2018-09-01 21:56  BruceLong  阅读(800)  评论(0编辑  收藏  举报