response=self.session.get(self.user_url.format(userid), headers=self.headers)
html=response.text
for key, value in self.font_dict.items():
if key in html:
html=html.replace(key, value)
assert 'dytk' in html
dytk=re.findall(r"dytk: '(.*?)'", html)[0]
tac=re.findall(r"<script>tac='(.*?)'</script>", html)[0]
html=etree.HTML(html)
nickname=html.xpath('//p[@class="nickname"]/text()')[0]
douyinid=''.join(html.xpath('//p[@class="shortid"]/i/text()'))
num_followers=''.join(html.xpath('//span[@class="follower block"]/span[1]//text()')).strip()
num_videos=''.join(html.xpath('//div[@class="user-tab active tab get-list"]/span/i/text()'))
'''视频下载'''
def __download(self, download_url, savename, savedir='.'):
print('[INFO]: 正在下载 ——> %s' % savename)
if not os.path.exists(savedir):
os.mkdir(savedir)
with closing(self.session.get(download_url, headers=self.ios_headers, stream=True, verify=False)) as response:
total_size=int(response.headers['content-length'])
if response.status_code==200:
label='[FileSize]:%0.2f MB' % (total_size/(1024*1024))
with click.progressbar(length=total_size, label=label) as progressbar:
with open(os.path.join(savedir, savename+'.mp4'), "wb") as fp:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
fp.write(chunk)
progressbar.update(1024)