This is a reprint, download picture video about Python

Source: Internet
Author: User

Objective: To familiarize yourself with the difference between Python's powerful data processing capabilities and python2,3

Scene: Paste on the picture, the data structure of the huge XML, some foreign more hot resource sharing platform, you like the comic, want to see the movie, as long as the resources are good, Python can help you achieve find, connect to download.

Principle: Actually can not put pictures, feel 51CTO this kind of blog, beginner's mind is good, also slowly become a bad use of things, when a business set up, his mission is just to earn money. It's a pity.


Principle: You need to analyze the target site, the Web address you need is? Generally in the src= "", with regular simple to match a bit can be. If it's a bit complicated, then use a professional tool to analyze it.

Fiddler or Http_watch


The language for Python is a lot simpler. Here's an introductory quiz. Reproduced. Http://www.cnblogs.com/fnng/p/3576154.html

I'm going to go to cnblogs, too.


Content: This small test is mainly three aspects:

1. Try to set up an HTTP request, mostly using Urllib's requests Urlopen

Import reimport urllib.requestdef gethtml (URL):p age = Urllib.request.urlopen (URL) html = page.read () #html = Html.decode ( ' Utf-8 ') return HTML

2, try to write a regular to match the SRC or the link you need?

About the regular, I have something to say, can refer to the classic book <awk&sed>, and then must use a regular test tool, recommend the regex, like a small tiger, not found, in another computer.

Then reproduced

Import reimport urllibdef gethtml (URL): page = urllib.urlopen (URL) html = page.read () return htmldef getimg (HTML)         : Reg = R ' src= "(. +?\.jpg)" Pic_ext ' Imgre = Re.compile (reg) imglist = Re.findall (imgre,html) return imglist html = gethtml ("http://tieba.baidu.com/p/2460150866") print getimg (HTML)

The main use of the R ' regular ', here is a small problem, it must be decode, that is, HTML, get the interface results, need to Html.decode (' Utf-s '), string into Unicode

Explanation: The representation of a string inside Python is Unicode encoding, therefore, in encoding conversion, it is usually necessary to use Unicode as the intermediate encoding, that is, decoding the other encoded string (decode) into Unicode first


3, or to establish a connection, download the second resource, save up on the end, now think, or cloud technology good ah, we are just porters, why to download to the local. Last reproduced

def getimg (HTML): Reg = R ' src= "(. +?\.jpg)" Pic_ext ' Imgre = Re.compile (reg) imglist = Re.findall (imgre,html) x = 0 for Imgurl in Imglist:urllib.urlretrieve (Imgurl, '%s.jpg '% x) x+=1 return imglist

It's basically over. If you are interested in this, you can search your own study, this is a tool language, quite efficient and useful.

As for his Python environment, both window and Linux are easier to fix.

If you think about it further, you can learn to use Docker to bump into his environment. Python is the same age as me.

I still become original, the above part of the code to the adults are not Chinese, gentleman pragmatic. Independent blog: HTTP://WWW.TESTPUB.CN

(There are python on the Internet for various resources, such as Tum. B.. L ... R.. )


This article is from the "one-stop solution" blog, so be sure to keep this source http://10725691.blog.51cto.com/10715691/1941407

This is a reprint, download picture video about Python

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.