In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces python multi-thread how to climb cat's eye movie, the article is very detailed, has a certain reference value, interested friends must finish!
Through the multithreading of python3, the top100 movie list of cat's eye movies is obtained, and the information is saved locally, using the requests library and regular expressions.
#! / usr/bin/env python#-*-coding: utf-8-*-# @ Author: Aiker Zhao# @ Date: 2:52 on 2019-4-2 AM# @ File: pamaoyan.py# @ Desc: import requestsfrom requests.exceptions import RequestExceptionimport reimport jsonfrom multiprocessing import Pooldef get_one_page (url): try: response = requests.get (url) if response.status_code = = 200: return response.text Return None except RequestException: return Nonedef parse_one_page (html): pattern = re.compile ('. *? board-index.*? > (\ d +). *? data-src= "(. *?)". *? name "> (. *?). *? star" > (. *?)
'+'. *? releasetime "> (. *?) (. *?). Re.S) pattern1 = re.compile ('board-index.*? > (\ d +). *? data-src=" (. *?) ". *? name" > (. *?). Star "> (. *?)
', re.S) items = re.findall (pattern, html) # print (items) for item in items: yield {' index': item [0], 'score': item [5] + item [6],' image': item [1], 'title': item [2],' actor': item [3] .strip () [3:] 'time': item [4] [5:]} def write_to_file (content): with open (' result.txt', 'asides, encoding='utf-8') as f: f.write (json.dumps (content) Ensure_ascii=False) +'\ n') f.close () def main (offset): url = 'https://maoyan.com/board/4?offset=' + str (offset) html = get_one_page (url) # print (html) for item in parse_one_page (html): print (item) write_to_file (item) if _ name__ = =' _ main__': # For i in range (10): # main (iTunes 10) pool = Pool () pool.map (main [I * 10 for i in range (10)]) these are all the contents of the article "how does python multithread climb Cat's Eye Movie" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.