Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import json
- screen_name = "mynamekamikaze"
- URL = "https://twitter.com/" + screen_name
- r = requests.get(URL)
- # スクリーンネーム変更もしくは削除で404
- # 凍結は200で通常の状態と区別出来ないのでリダイレクト先のURLを参照する
- print(r.status_code)
- # スクリーンネーム変更もしくは削除時の処理
- if (r.status_code==404):
- print("hello")
- # 凍結時の処理
- elif(r.url == "https://twitter.com/account/suspended"):
- print("suspended")
- # それ以外の処理
- else:
- #ページ全体をsoupに格納
- soup = BeautifulSoup(r.content, 'lxml')
- # 特定のタグの取得
- span = soup.find_all("ul",class_="ProfileNav-list")[0].find_all("span")
- div = soup.find_all("li", class_="js-stream-item stream-item stream-item ")[0].find("div")
- # 要素の取得
- id_ = div.attrs["data-user-id"]
- name = div.attrs['data-name']
- screen_name = div.attrs["data-screen-name"]
- followers_count = span[8].attrs["data-count"]
- friends_count = span[5].attrs["data-count"]
- statuses_count = span[2].attrs["data-count"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement