Skip to content

Instantly share code, notes, and snippets.

@koheso
Last active January 20, 2018 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koheso/36285bba45bb17fea2101d226433ae4f to your computer and use it in GitHub Desktop.
Save koheso/36285bba45bb17fea2101d226433ae4f to your computer and use it in GitHub Desktop.
スクレイピングでCoinmarketcapのデータをスクレイピング
import requests
from bs4 import BeautifulSoup
from datetime import datetime
#URLの指定
url = 'https://coinmarketcap.com/'
#ユーザージェントの設定
headers = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0",
}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.text.encode(r.encoding),'lxml')
#trをすべて取得
for tr in soup.find_all('tr'):
coinCon = tr.find("a")
if coinCon != None:
coinName = coinCon.text
price = tr.find("a", { "class" : "price" })
rate = tr.find("td", {"class" : "percent-24h"})
print("■" + coinName)
print("price:" + price.text)
print("rate24h:" + rate.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment