# coding: utf-8
import requests
import re
from bs4 import BeautifulSoup
url = 'https://www.appannie.com/account/login/?_ref=header'
session = requests.Session()
session.headers['user-agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36'
session.get(url)
token = session.cookies.get('csrftoken')
print(token)
header = {
"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
"Host": "www.appannie.com",
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain,*/*',
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8',
'X-NewRelic-ID': 'VwcPUFJXGwEBUlJSDgc=',
'X-Requested-With': 'XMLHttpRequest',
}
data = {
'csrfmiddlewaretoken': token,
'next': '/dashboard/home/',
'username': '1@qq.com',
'password': '1'
}
cookies = session.cookies
r = session.post(url, data)
#url_1 = "https://www.appannie.com/ajax/top-chart/table/?market=google-play&country_code=US&category=1&date=2018-12-26&rank_sorting_type=rank&page_size=100&order_type=desc"
req_1 = session.get(url_1, headers=header, cookies=cookies)
req_1.encoding = 'utf-8'
content = req_1.text
p1 = "apps/google-play/app/(.*?)/details/"
pattern1 = re.compile(p1)
print(pattern1.findall(content))
下面数据是我自己想要的数据,你可以根据正则提取你自己想要的数据