In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Python how to crawl express 100 can query logistics information, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
The text and pictures of this article come from the network, only for learning, communication and use, do not have any commercial use, the copyright belongs to the original author, if you have any questions, please contact us in time to deal with.
We often check the logistics order numbers of express delivery, but where do these logistics order numbers come from?
Express bird gathered a number of express companies query interface, input the corresponding express company code and express order number can obtain the corresponding logistics information is very convenient and fast.
Project goal
Teach people how to use Python programming to query their own logistics information.
2. Find
Query?type=shentong&postid=773036432685909&temp=0.0
This file. Find Request URL: copy the URL.
3. Analysis website:
Https://www.kuaidi100.com/query?type=shentong&postid=773036432685909&temp=0.03191355265516216&phone=
4. You can see that postid is our express order number, and type is the abbreviation of pinyin for the names of each express company. Later, you can define this dictionary to store the concatenated URLs of the names of each company.
5. Find the data corresponding to Preview= > > and you can see that context is the logistics information. The corresponding fields can be obtained later through js parsing.
Project realization
1. Define a class class that inherits object. Import the required libraries and URLs. Define a dictionary kd_dict to store express company abbreviation.
Import urllib.requestimport jsonkd_dict = {1: 'shentong', 2:' youzhengguonei', 3: 'yuantong', 4:' shunfeng', 5: 'yunda', 6:' zhongtong'} class YU (object): pass
2. Establish the query framework.
While True: print ("enter to query the express company:") print ("1. Shentong 2.EMS Post 3. Yuantong 4. Downwind 5. The rhyme reaches 6. Zhongtong 0. Exit\ n ") choose = int (input (" Please select your express company: ") while choose not in range (0,7): choose = int (input (" Sorry not supporting this company for the time being, please re-select: ") if choose = 0: break kd_num = input (" Please enter the express order number: ")
3. Parse the js file.
Url = "http://www.kuaidi100.com/query?type=%s&postid=%s"% (kd_dict [choose], kd_num) response = urllib.request.urlopen (url) html = response.read () .decode ('utf-8') target = json.loads (html)
4. Determine whether the status is 200 or not. Only 200 can be accessed normally, and the corresponding data can be obtained.
If status = '200: data = target [' data'] # print (data) data_len = len (data) # print (data_len) # print ("\ n")
5. Iterate through for to get the corresponding fields.
For i in range (data_len): print ("\ ntime:" + data [I] ['time']) print ("status:" + data [I] [' context'] + ") print ("\ nThank you for using!\ n ") breakelse: print (" Please re-enter it!\ n ")
6. Program cycle.
While True: YU.Check () out = input ("Press any number to exit (other keys continue).") If out > ='0' and out
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.