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 get High quality Ultra clear wallpaper by Python

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces "how Python climbs high-quality ultra-clear wallpaper". In daily operation, I believe many people have doubts about how to climb high-quality ultra-clear wallpaper by Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to climb high-quality ultra-clear wallpaper by Python". Next, please follow the editor to study!

Basic development environment

Python 3.6

Pycharm

The use of related modules import requestsimport reimport os

Install Python and add it to the environment variable, and pip installs the relevant modules you need.

First, define the needs

Crawl the HD wallpaper inside as shown in the picture

Second, web page data analysis

So just get this link and climb the wallpaper picture.

If you return to the list, you will find that the web page is loaded in a waterfall stream, and the data will appear only when you slide down. So you can open the developer tool before you slide down the page, and the newly loaded data will appear when you slide down the page.

By comparison, you can see that this packet contains the address of the wallpaper picture download.

It is important to note that this data link is a post request, not a get request.

The data parameter to be submitted is the corresponding page number.

Third, code implementation

1. Get the image ID

For page in range (1,11): url = 'https://wallpaper.wispx.cn/cat/%E5%8A%A8%E6%BC%AB' headers = {' user-agent': 'Mozilla/5.0 (Windows NT 10.0) WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36', 'x requestedhouse withdrawing: 'XMLHttpRequest',} data = {' page': page} response = requests.post (url=url, headers=headers) result = re.findall ('detail (. *?) target=' Response.text) for index in result: image_id = index.replace ('\',''). Replace ('','') page_url = f 'https://wallpaper.wispx.cn/detail{image_id}'

2. Get the wallpaper url address and save it

Def main (page_url): html_data = get_response (page_url). Text image_url = re.findall (', html_data) [0] image_title = re.findall ('(. *?)' Html_data) [0] .split ('-') [0] image_content = get_response (image_url). Content path = 'images\\' if not os.path.exists (path): os.makedirs (path) with open (path + image_title + '.jpg', mode='wb') as f: f.write (image_content) print ('saving:', image_title)

Points to pay attention to:

Hotlink protection is required in the request header, otherwise it cannot be downloaded.

Def get_response (html_url): header = {'referer':' https://wallpaper.wispx.cn/detail/1206', 'User-Agent':' Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'} resp = requests.get (url=html_url, headers=header) return resp IV.

At this point, the study on "how to climb high-quality ultra-clear wallpaper by Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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

Internet Technology

Wechat

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

12
Report