Skip to content

Instantly share code, notes, and snippets.

@sholfen
Created April 5, 2016 11:37
Show Gist options
  • Save sholfen/85893856739982d400e0c5f02c33cddf to your computer and use it in GitHub Desktop.
Save sholfen/85893856739982d400e0c5f02c33cddf to your computer and use it in GitHub Desktop.
to get magnet link from dmhy twitter
# -*- coding: utf8 -*-
import twitter
import requests
import re
def get_magnet_link(url):
response = requests.get(url)
source_string = response.content
pattern = re.compile(r'(?<=id="a_magnet" href=")(.*?)">')
result = pattern.search(source_string)
if result:
print(result.group(1))
else:
print('no result')
api = twitter.Api(consumer_key='your_key',
consumer_secret='your_key',
access_token_key='your_key',
access_token_secret='your_key')
statuses = api.GetUserTimeline(screen_name='dmhyrss')
for s in statuses:
text = s.text.encode('utf8')
if text.startswith('[动画] 【脸肿字幕组】[粗点心战争'):
print(s.text)
if s.urls:
get_magnet_link(s.urls[0].expanded_url)
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment