Skip to content

Instantly share code, notes, and snippets.

@oiuww09fn
Last active November 9, 2015 06:55
Show Gist options
  • Save oiuww09fn/36dca41c329d901b9a32 to your computer and use it in GitHub Desktop.
Save oiuww09fn/36dca41c329d901b9a32 to your computer and use it in GitHub Desktop.
parse live.caipiao.163.com
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(requests.get("http://live.caipiao.163.com/jcbf/").text)
# soup = BeautifulSoup(requests.get("http://live.caipiao.163.com/dcbf/").text)
dd = soup.find_all("dd")
final_list = []
for i in dd:
final_list.append(
{
"matchid": i.get("matchid"),
"hostid": i.get("hostid"),
"visitid": i.get("visitid"),
"period": i.find("span", class_="period").string,
"events": i.find("span", class_="events").string,
"playTime": i.find("span", class_="playTime").string,
"round": i.find("span", class_="round").string,
"type": i.find("span", class_="type").string,
"host": i.find("span", class_="host").text.split()[1],
"guest": i.find("span", class_="guest").text.split()[0],
"half": i.find("span", class_="half").string,
"concede": i.find("span", class_="concede").string,
"results": i.find("span", class_="results").string,
"odds": [j.string for j in i.find("span", class_="odds").find_all("em")]
}
)
for i in final_list:
print i["matchid"], i["hostid"], i["visitid"], i["odds"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment