It’s been two months since I started learning python on my own. It all starts from the bottom of my heart, about what I really want to learn. To be honest, I genuinely feel that I’ve enjoyed this journey.
After reading related books and videos for quite a long time, I decided to get hands on the practice, which is more difficult as expected.
What drives me to write this small application is that I love watching sports games and I often checked a website, which is “www.zhibo8.cc”, to see what games are on live today. However, I found this action repetitive and a waste of time opening my website, selecting the bookmark and then scrolling down to the part which I want. I have tried several modules for web scraping and this time I chose to use BeautifulSoup to get the web page. Therefore, this module’s code is as follows:
from bs4 import BeautifulSoup
from datetime import *
url = 'http://www.zhibo8.cc/'
q = urllib2.urlopen(url)
soup = BeautifulSoup(q)
i = date.today()
today = soup.find(title=i)
#today1 = soup.find_all(class_='content')
#for i in today1:
# print i.li
today1 = today.next.next.next.next
for i in today1.ul:
if i.next.string == None:
print i.next.string + '\n' + i.next.next.string
It works pretty well and shows me what I need in the console. But after I came to the U.S., it started to raise an error saying the variable “today” is Nonetype. After debugging, I found it kind of funny because it is due to the time zone difference. Variable “i” here represents today in the U.S. while sometimes in China it is one day later. Obviously, the website “zhibo8” will delete all the live games information at the end of the day. So if I am lucky enough to run this application at night in Los Angeles, when it is tomorrow morning in China, I will encounter this error.
I plan to figure out a way to solve this problem later, and I am quite satisfied with my first executable python file after two months.