Joke Collection Website - Mood Talk - How to start using Python crawler
How to start using Python crawler
1, learn to use the function of parsing web pages, such as:
Import? urllib.request
What if? __name__? ==? __main__ ':
Website? =? "..."
Data? =? urllib.request.urlopen(url)。 read()? # urllib.request.urlope (URL to be parsed)
Data? =? data.decode('unicode_escape ',' ignore ')? # Decoding in unicode_escape mode
Print (data)
2. Learn regular expressions:
The symbolic meaning of regular expression is as follows. Regular expression filters out the information in the above data, for example:
Def get_all (data):
Reg = r' (search. +)(" )(mars_sead= "。 +title= ")(。 +)(" data-id= ")"
All = recompile (reg);
alllist = re.findall(all,data)
Return all lists
3. Press the result into the array:
What if? __name__? ==? __main__ ':
Information = []
info.append(get_all(data))
4. Write the array into excel:
Import xlsxwriter
What if? __name__? ==? __main__ ':
Information = []
info.append(get_all(data))
workbook = xlsxwriter . workbook(' C:\ \ Users \ \ Administrator \ \ Desktop \ \ What ' s file name。 xlsx’)? # Create an Excel file
Worksheet = workbook.add_worksheet ()? # Create a worksheet object
For I(0, len(info)) in the range:
Worksheet.write (row, column, info[i], font)# Write info[i] line by line.
Workbook.close()# Close excel
Simple reptiles did it, but advanced reptiles didn't teach it. You haven't touched it yet, so you can't understand it.
- Previous article:a man of iron
- Next article:Humor uncle loves to say sentences.
- Related articles
- Sad quotes from SpongeBob SquarePants
- A couple named Cao and a couple named Jiang use their surnames to connect them into a sentence, which means a lifetime's words. How to write it on the cup?
- The wonderful dialogue of storytelling is very short.
- A short message from a circle of friends on National Day (80 general sentences)
- 80 general comments on kindergartens in 2022
- Express the lonely mood in rainy days, talk about the crying rain, and fall to the ground.
- Suitable for sending humorous sentences in a circle of friends after running.
- Humorous words calm girls down.
- Talking about selfish love.
- Talk about the best lover