Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to give your baby a good name with the help of Python crawler

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces you how to give your baby a good name with Python crawler. The content is very detailed. Interested friends can refer to it for reference. I hope it can help you.

There is one thing that happens to everyone in life that they don't care about until it happens, but once it happens, they find it extremely important and they need to make a big decision in a very short time, and that is to name their newborn baby. Because you have to name your baby within two weeks of birth.(I need to apply for a birth certificate). It is estimated that many people are like me. At first, they were very flustered. Although I felt that Chinese characters were very many, I could just find a word to make a name. Later, I found that it was really not a casual thing. I found it inappropriate no matter how I thought about it. So I turned over dictionaries, searched online, turned over Tang and Song poems, poems and even martial arts novels everywhere. However, the names I got after thinking for a long time were often subject to opinions and objections from family members, such as not being fluent, and repeating names with relatives. This leads to a cycle of repeated search and denial, which becomes more and more chaotic.

There is one thing that happens to everyone in life that they don't care about until it happens, but once it happens, they find it extremely important and they need to make a big decision in a very short time, and that is to name their newborn baby.

Because you have to name your baby within two weeks of birth.(I need to apply for a birth certificate). It is estimated that many people are like me. At first, they were very flustered. Although I felt that Chinese characters were very many, I could just find a word to make a name. Later, I found that it was really not a casual thing. I found it inappropriate no matter how I thought about it. So I turned over dictionaries, searched online, turned over Tang and Song poems, poems and even martial arts novels everywhere. However, the names I got after thinking for a long time were often subject to opinions and objections from family members, such as not being fluent, and repeating names with relatives. This leads to a cycle of repeated search and denial, which becomes more and more chaotic.

So we went back to various searches on the Internet again and found many articles such as "A Complete Collection of Nice Names for Male Babies" given online. These articles suddenly gave hundreds of thousands of names, which were too dazzling to use. And there are a lot of test name website or APP, input name can give eight characters or five grid score, such function feels good can give a reference, but either we need a name input for testing, or these websites or APP own name is very few, or can not meet our needs such as limited words, or start charging, to the end also can not find a good use.

So I wanted to make this program:

The main function is to provide a batch of names to provide reference, these names are combined with the baby's birth characters calculated;

He could expand his name library. For example, if he found a batch of good names in the Book of Songs on the Internet, he would like to see what they look like and add them in.

The use of words for names can be limited. For example, some family genealogies have restrictions. At present, they are "Guo" characters. The name must have the word "Guo".

The list of names can be rated, so that when the list is reversed, the names can be viewed from high to low;

In this way, we can get a list of names that match our child's birth characters, our family tree restrictions, and our preferences, and this list has given scores for reference, which we can use as a benchmark to find the favorite names one by one. Of course, if you have a new idea, you can always add a new name to the thesaurus and recalculate it.

Code structure of program

Code introduction:

/chinese-name-score code root directory

/chinese-name-score/main Code directory

The requested URL/main/dicts/was not found on this server.

The requested URL/main/dicts/names_boys_double.txt was not found on this server.

/chinese-name-score/main/dicts/names_boys_single.txt dictionary file, boy's single name

The requested URL/main/dicts/names_girls_single.txt was not found on this server.

/chinese-name-score/main/dicts/names_grils_double.txt Dictionary file, girl's single name

The requested URL/main/outputs/was not found on this server.

The requested URL/main/outputs/names_girls_source_wxy.txt was not found on this server.

The requested URL/main/scripts.php was not found on this server.

The requested URL/main/scripts/unique_file_lines.py was not found on this server.

/chinese-name-score/main/sys_config.py system configuration of the program, including the crawl target URL, dictionary file path

/chinese-name-score/main/user_config.py User configuration of the program, including the baby's date, time, gender, etc.

The requested URL/main/get_name_score.py was not found on this server.

How to use the code:

If there is no qualified word, find the dictionary files name_boys_double.txt and name_grils_double.txt, you can add some names you find here, and add them in *** by line division;

If there are qualified words, find the dictionary files names_boys_single.txt and names_girls_single.txt, add your favorite single word list here, and add it in *** by line division;

Open user_config.py and configure it. See the next section for configuration items.

Run the script get_name_score.py

In the outputs directory, view your own output files, copy them to Excel, sort them, etc.;

configuration entry for program

The configuration of the program is as follows:

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

# coding:GB18030

"""

Write the configuration here

"""

setting = {}

#qualified word, if configured, will take the word dictionary, otherwise take the word dictionary

setting["limit_world"] = "country"

#Last name

setting["name_prefix"] = "Li"

#Gender, male or female

setting["sex"] = "male"

#Province

setting["area_province"] = "Beijing"

#City

setting["area_region"] = "Haidian"

#Gregorian year of birth

setting['year'] = "2017"

#Calendar month of birth

setting['month'] = "1"

#Calendar day of birth

setting['day'] = "11"

#Gregorian hour of birth

setting['hour'] = "11"

#Gregorian minutes of birth

setting['minute'] = "11"

#Result Output File Name

setting['output_fname'] = "names_girls_source_xxx.txt"

According to the setting["limit_world"], the system automatically decides whether to choose a single dictionary or a multiple dictionary:

If this item is set, such as equal to "country", then the program will combine all words into names for calculation, such as Guohao and Haoguo two names will be calculated;

If you leave this option blank, the program will read only the double-word dictionary of *_double.txt

Principles of the program

This is a simple reptile. You can open http://life.httpcn.com/xingming.asp website to view, this is a POST form, fill in the required parameters, click submit, will open a result page, the bottom of the result page contains eight characters score and five grid score.

If you want to get a score, you need to do two things: one is to automatically submit the form and get the result page; the other is to extract the score from the result page;

For *** things, it's easy, urllib2 can be implemented (code in/chinese-name-score/main/get_name_score.py):

Python

1

2

3

post_data = urllib.urlencode(params)

req = urllib2.urlopen(sys_config.REQUEST_URL, post_data)

content = req.read()

Here params is a parameter dict, in this way, POST with data submission, and then get the result data from content.

Params parameters are set as follows:

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

params = {}

#Date type, 0 means Gregorian calendar, 1 means lunar calendar

params['data_type'] = "0"

params['year'] = "%s" % str(user_config.setting["year"])

params['month'] = "%s" % str(user_config.setting["month"])

params['day'] = "%s" % str(user_config.setting["day"])

params['hour'] = "%s" % str(user_config.setting["hour"])

params['minute'] = "%s" % str(user_config.setting["minute"])

params['pid'] = "%s" % str(user_config.setting["area_province"])

params['cid'] = "%s" % str(user_config.setting["area_region"])

#Happy to use the five elements, 0 means automatic analysis, 1 means self-determined happy to use God

params['wxxy'] = "0"

params['xing'] = "%s" % (user_config.setting["name_prefix"])

params['ming'] = name_postfix

#means female, 1 means male

if user_config.setting["sex"] == "male":

params['sex'] = "1"

else:

params['sex'] = "0"

params['act'] = "submit"

params['isbz'] = "1"

The second thing is to extract the required score from the web page. We can use Beautiful Soup 4 to achieve this. Its syntax is also very simple:

Python

1

2

3

4

5

6

7

8

9

10

11

12

13

soup = BeautifulSoup(content, 'html.parser', from_encoding="GB18030")

full_name = get_full_name(name_postfix)

# print soup.find(string=re.compile(u"name five grid score"))

for node in soup.find_all("div", class_="chaxun_b"):

node_cont = node.get_text()

if u'name five-grid rating' in node_cont:

name_wuge = node.find(string=re.compile(u"name five grid score"))

result_data['wuge_score'] = name_wuge.next_sibling.b.get_text()

if u'name eight character rating' in node_cont:

name_wuge = node.find(string=re.compile(u"name eight character rating"))

result_data['bazi_score'] = name_wuge.next_sibling.b.get_text()

Through this method, we can parse HTML and extract the scores of eight characters and five squares.

Operation Result Case 1

2

3

4

5

6

7

8

9

10

11

12

1/1287 Li Guojin's name score =61.5, name score =78.6, total score =140.1

2/1287 Li Guotie's name score =61, name score =89.7, total score =150.7

3/1287 Li Guojing's name eight character score =21 name five grid score =81.6 total score =102.6

4/1287 Li Mingguo's name eight character score =21 name five grid score =90.3 total score =111.3

5/1287 Li Rouguo's name eight characters score =64 name five grid score =78.3 total score =142.3

6/1287 Li Guojing's name eight character score =21 name five grid score =89.8 total score =110.8

7/1287 Li Guodi's name eight character score =22 name five grid score =87.2 total score =109.2

8/1287 Li Guodeng's name eight character score =21 name five grid score =81.6 total score =102.6

9/1287 Li Luoguo's name eight characters score =21 name five grid score =83.7 total score =104.7

10/1287 Li Guotian's name eight character score =21 name five grid score =81.6 total score =102.6

11/1287 Li Guotian's name eight character score =22 name five grid score =83.7 total score =105.7

12/1287 Li Guotian's name eight character score =22 name five grid score =93.7 total score =115.7

With these scores, we can sort them, and it's a useful reference.

friendly reminder

Scores are related to many factors, such as birth time, limited words, limited strokes and other factors, these conditions determine that some names will not score high, do not be affected by this, find out the relatively high score can be;

At present, the program can only crawl the content of one website, the address is life.httpcn.com/xingming.asp

This list is for reference only. I have read some articles. In history, many famous people and great men have very low scores on their names and characters, but they have all made contributions. The names do have some influence, but sometimes catchy is the best.

After selecting the name from this list, you can check it in Baidu, Renren. com and other places to prevent some negative people from repeating their names, or too many people with this name are rotten streets;

Eight-character score is Chinese inheritance, five-grid score is invented by Japanese in modern times, sometimes you can also try western constellation naming method, and strange is that eight characters and five scores differ greatly from each other on different websites, which shows that this thing is only for reference;

About how to use Python crawler to give the baby a good name to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report