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

正则匹配找规律


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))

相关文章:

  • 2021-12-04
  • 2021-11-19
  • 2021-11-19
  • 2021-10-01
  • 2021-04-20
  • 2021-09-18
  • 2021-04-14
  • 2021-07-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-13
  • 2021-05-01
  • 2021-07-15
  • 2021-07-10
  • 2022-12-23
相关资源
相似解决方案