The author | Ding Yanjun

Source | love learning Python (ID: sldata2017)

Please contact authorization for reprinting (wechat ID: ex: 239 zhong: 460 Post: 8316)

Two days ago, I saw an interesting question on the Internet: is lottery prediction reliable? Why do so many people still believe in lottery predictions?

Aside from that, are lottery predictions accurate? Lottery ticket forecast also divides a person and different, legerdemain on river’s lake is very much, some can think the accuracy of lottery ticket forecast can be very high even by mistake, these drive dish gimmick, the colourful people that lets not know principle is most willing to take out money to buy material.

In lottery prediction, there are also serious to study the “law”, nothing more than three “factions” : data, graphics, formula. There is a school not included: the school of crossword painting, can be included in the ranks of neuropathy.

Which of these predictions is accurate? No, because I hardly ever buy lottery tickets (for fun, entertainment) or do any research. But any party has to have data to study, and today I’m just going to help you get all the data (winning numbers, winning bets, sales, percentage of returns, etc.) from the beginning of 3D lottery.

When climbing some simple (no anti-crawling mechanism) static web pages, the general strategy is: select the target (the so-called URL link), observe the structure (link structure, page structure), conception (choose what HTML downloaders, parsers, etc.). In the crawler process, three kinds of tools are involved:

HTML downloader: Download HTML web pages

 

HTML parser: Parses valid data

 

Data storage: The storage of valid data in the form of files or databases

Today, we’ll use the Requests library and The BeautifulSoup module to grab the blessing 3D information of the lottery web page and save it to an Excel table.

Before you start, take a look at the structure of the target page:

 

 

 

Hello: If you are the one! If you are learning Python or are planning to learn it, you can make up “01” to get information!

You can see that the URL of the target page changes one at a time: the number after list_x represents the page number.

 

Then, looking at the web page structure, again very simply, you can see that the source code for the lottery information in the first issue is a TR node, and we can use BeautifulSoup library to extract some of that information.

The overall idea is: If you want to obtain all the information (246 pages in total) of Fucai 3D since its establishment 14 years ago, you only need to separate 246 requests. After obtaining different pages, you can obtain all the information of Fucai 3D by extracting relevant information from BeautifulSoup library and writing data into Excel using XLRD library. The results are as follows:

 

 

 

The detailed code is as follows:

Import requests from bS4 import BeautifulSoup import XLWT import time def get_one_page(url): Headers = {' user-agent ':'Mozilla/5.0 (Windows NT 6.1; Win64; X64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/64.0.3282.140 Safari/537.36'} Response = requests == 200: return response.text return None # def parse_one_page(HTML): soup = BeautifulSoup(html,'lxml') i = 0 for item in soup.select('tr')[2:-1]: yield{ 'time':item.select('td')[i].text, 'issue':item.select('td')[i+1].text, 'digits':item.select('td em')[0].text, 'ten_digits':item.select('td em')[1].text, 'hundred_digits':item.select('td em')[2].text, 'single_selection':item.select('td')[i+3].text, 'group_selection_3':item.select('td')[i+4].text, 'group_selection_6':item.select('td')[i+5].text, 'sales':item.select('td')[i+6].text, Select ('td')[I +7].text} # def write_to_excel(): f = xlwt.Workbook() sheet1 = f.add_sheet('3D',cell_overwrite_ok=True) row0 = [" date ", "" issue", "single", "ten", "best figures", "odd", "group 3", "group choose 6", "sales", "proportion of slipper"] # write the first line for j in range (0, len (row0)) : Sheet1.write (0,j,row0[j]) # sheet1.write(0,j,row0[j]) # Url = 'http://kaijiang.zhcw.com/zhcw/html/3d/list_%s.html' % (STR) (k) HTML = get_one_page (url) print (' are preserved in the first page % d. For item in parse_one_page(HTML): Sheet1. Write (I + 1, 0, item [' time ']) sheet1. Write (I + 1, 1, item [' issue ']) sheet1. Write (I + 1, 2, item [' who ']) Sheet1. Write (I + 1, 3, item [' ten_digits']) sheet1. Write (I + 1, 4, item [' hundred_digits']) Sheet1. Write (I + 1, 5, item [' single_selection ']) sheet1. Write (I + 1, 6, item [' group_selection_3 ']) Sheet1. Write (I + 1, 7, item [' group_selection_6 ']) sheet1. Write (I + 1, 8, item [' sales']) sheet1. Write (I + 1, 9, item [' return_rates'])  i+=1 f.save('3D.xls') def main(): write_to_excel() if __name__ == '__main__': main()Copy the code

Up to now, the 3D information about 14 years of lucky lottery can be climbed down, as for how to predict? What’s the trend of the next lottery? Don’t know also won’t, next whether win prize, depend on you. Gamblers, that’s as far as I can take you!

Finally, are lottery predictions accurate or not? I’m not going to go into too much theoretical analysis, but JUST two questions:

Proposition 1: take the dichromatic ball as an example, what is the probability of winning the next two groups of numbers,1,2,3,4, 4,5,6,7 and 3,4,8,11,22,29,7? Who is higher and who is lower or is it all the same?

Proposition 2: The second question is easier. Let’s say you’ve flipped a coin nine times and it’s all heads. Now you’re going to take the 10th shot, what’s the probability of getting heads?

 

If you ask me again, is there a pattern to the lottery? As far as I’m concerned, the lottery rules are that there are no rules (believe me, you have to analyze all the data for 14 years) that human computing can’t calculate, if at all. Lottery is entertainment, is a game of luck, even if a person made money in the lottery, good luck, does not mean that the method used can improve the lottery winning rate. Any attempt to make money in the name of increasing the winning rate, even if the intention is well-intentioned, will eventually go wrong.

The essence of XX’s lottery (especially the black lottery) is to create an unearned person, fool a group of people who want to get something for nothing, and eventually feed a group of people who really get something for nothing.