Python implementation query Apple phone repair Progress _python

Source: Internet
Author: User

The evil Apple, my 5s recently broke, the official retail store is simply not a reservation ah, no appointment ah, so had to find the authorized repair point, yesterday after the people said may have to return to the factory, the cycle about 20 days, I directly drunk, 20 days ah, fast one months ah, such as mobile phone hands are almost pure, Fuck. This afternoon boring online search can find the repair progress, found in the Apple official website can be viewed, but my camera has not been sent to repair, and now still do not find repair progress, while boring nothing dry, wrote a program to even view the maintenance progress.

Python's urllib2 has added support for cookies, which is handy for crawling some sites to log on to or setting up cookies.

and the URLLIB2 module supports debug mode, you can see your program sent to the server request has been returned by the server information, so you can easily see if your program has problems.
Okay, let's not talk nonsense, here's the code.

Copy Code code as follows:

From BS4 import BeautifulSoup
Import Urllib2
Import Urllib
Import Cookielib


Urllib2.urlopen (' http://www.baidu.com '). Read ()

Baseurl= ' https://selfsolve.apple.com/repairstatus/GetRepairDetails.do '

headers = {
' Accept ': ' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8 ',
' Host ': ' selfsolve.apple.com ',
' Origin ': ' https://selfsolve.apple.com ',
' Referer ': ' Https://selfsolve.apple.com/repairstatus/main.do ',
' Accept-language ': ' zh-cn,zh;q=0.8,en-us;q=0.6,en;q=0.4 ',
' Cache-control ': ' max-age=0 ',
' Connection ': ' Keep-alive ',
' Content-length ': 45,
' Content-type ': ' application/x-www-form-urlencoded ',
' User-agent ': ' mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/34.0.1847.116 safari/537.36 ',
}


postdata={
' repair_id ': ' aaaaaa ', #维修序号
' Serial_number ': ' bbbbb ' #手机序列号
}


If __name__== ' __main__ ':

CJ = Cookielib. Lwpcookiejar ()
Cookie_support = Urllib2. Httpcookieprocessor (CJ)
Opener = Urllib2.build_opener (
Cookie_support,
Urllib2. HttpHandler (debuglevel=1),
Urllib2. Httpshandler (debuglevel=1)
)

Urllib2.install_opener (opener)




Strpostdata=urllib.urlencode (PostData)
Req=urllib2. Request (Baseurl,strpostdata,headers)
Rsp=urllib2.urlopen (req)
Text=rsp.read ()

File=open (' repair.html ', ' W ')
File.write (text)
File.close ()

Print text
Raw_input ()

Well, that's the way the program is, the addition of cookies to support and open debug mode is the following code

Copy Code code as follows:

CJ = Cookielib. Lwpcookiejar ()
Cookie_support = Urllib2. Httpcookieprocessor (CJ)
Opener = Urllib2.build_opener (
Cookie_support,
Urllib2. HttpHandler (debuglevel=1),
Urllib2. Httpshandler (debuglevel=1)
)

Urllib2.install_opener (opener)

Then you can easily see the program run the output, the following figure

The next step is to grab the required information through the resulting HTML.

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.