Query the repair progress of an Apple mobile phone using python

Source: Internet
Author: User
Tags set cookie
This article describes how to query the repair progress of an Apple mobile phone using python. The most important thing here is how to set cookie support and enable the debugging mode in python, if you need a friend, you can refer to the evil apple. my 5s broke down recently, and the official retail store could not make an appointment at all, so I had to find an authorized repair site, after the delivery yesterday, people said they might want to return to the factory. the cycle is about 20 days. I got drunk directly. 20 days, it's almost a month. when the phone gets ready, it's almost clear, fuck. this afternoon, I was bored and searched online to see if I could check the repair progress. I found that I could check the repair progress on the Apple official website. However, I still cannot find the repair progress, while bored, I wrote a program to check the repair progress.

Python urllib2 has added support for cookies, which is convenient for capturing websites to log on or set cookies.

In addition, the urllib2 module supports debugging mode. you can see that the request sent by your program to the server has been returned by the server, so that you can easily check whether your program has any problems.
Okay, let's not talk nonsense. the code below will be posted

The code is 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 = 100 ',
'Host': 'selfsolve .apple.com ',
'Origin': 'https: // selfsolve.apple.com ',
'Referer': 'https: // selfsolve.apple.com/repairstatus/main.do ',
'Accept-color': 'zh-CN, zh; q = 0.8, en-US; q = 0.6, en; q = 100 ',
'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/1234 ',
}


PostData = {
'Repair _ id': 'aaaaa', # Service No.
'Ial _ number': 'bbbbbb' # mobile phone serial number
}


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 ()

File1_open('repair.html ', 'w ')
File. write (text)
File. close ()

Print text
Raw_input ()

Okay, the program is like this. the following code is used to add cookie support and enable the debugging mode.

The code is 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 output when the program is running, as shown in figure

Next we can capture the required information through the html.

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.