Поэтому я делаю небольшой сценарий, который я распечатываю каждый раз, когда в основном происходит обновление моего отслеживания UPS.
Сейчас я сделал скрипт, который выглядит так:
tracking_full_site = 'https://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=' + url #URL is the last tracking numbers that I can't provide due to incase someone changes anything with my tracking.
headers = {
'User-Agent': ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36'
' (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36')
}
resp = s.get(tracking_full_site, headers=headers, timeout=12)
resp.raise_for_status()
bs4 = soup(resp.text, 'lxml')
old_list = []
for item in bs4.findAll('tr', {'valign': 'top'}):
where_is_it = " ".join(item.text.split())
old_list.append(where_is_it)
print(old_list)
sys.exit()
Однако получаемые оттиски:
United States 28.08.2018 6:16 Package departed international carrier facility
Edgewood, NY, United States 27.08.2018 20:00 Package transferred to post office
United States 27.08.2018 18:42 Package processed by international carrier
EDGEWOOD, NY, United States 24.08.2018 15:51 Package processed by UPS Mail Innovations origin facility
24.08.2018 12:55 Package received for processing by UPS Mail Innovations
United States 22.08.2018 8:19 Shipment information received by UPS Mail Innovations
, которая выглядит очень хорошо с функцией " ".join(item.text.split())
У меня вопрос , как я могу разделить его так, чтобы я мог распечатать только страну и т.д. или дату, время или описание?
EDIT:
Это полный HTML-код, который хотят видеть все:
<table summary="" border="0" cellpadding="0" cellspacing="0" class="dataTable">
<tbody>
<tr>
<th scope="col">Location</th>
<th scope="col">Date</th>
<th scope="col">Local Time</th>
<th scope="col" class="full">Activity (<a class="btnlnkR helpIconR" href="javascript:helpModLvl('https://www.ups.com/content/se/en/tracking/tracking/description.html')">What's this?</a>)</th>
</tr>
<tr valign="top">
<td class="nowrap">
United States
</td>
<td class="nowrap">
28.08.2018
</td>
<td class="nowrap">
6:16
</td>
<td>Package departed international carrier facility</td>
</tr>
<tr valign="top" class="odd">
<td class="nowrap">
Edgewood,
NY,
United States
</td>
<td class="nowrap">
27.08.2018
</td>
<td class="nowrap">
20:00
</td>
<td>Package transferred to post office</td>
</tr>
<tr valign="top">
<td class="nowrap">
United States
</td>
<td class="nowrap">
27.08.2018
</td>
<td class="nowrap">
18:42
</td>
<td>Package processed by international carrier</td>
</tr>
<tr valign="top" class="odd">
<td class="nowrap">
EDGEWOOD,
NY,
United States
</td>
<td class="nowrap">
24.08.2018
</td>
<td class="nowrap">
15:51
</td>
<td>Package processed by UPS Mail Innovations origin facility</td>
</tr>
<tr valign="top">
<td class="nowrap">
</td>
<td class="nowrap">
24.08.2018
</td>
<td class="nowrap">
12:55
</td>
<td>Package received for processing by UPS Mail Innovations</td>
</tr>
<tr valign="top" class="odd">
<td class="nowrap">
United States
</td>
<td class="nowrap">
22.08.2018
</td>
<td class="nowrap">
8:19
</td>
<td>Shipment information received by UPS Mail Innovations</td>
</tr>
</tbody>
</table>
Мое желание для вывода будет и т. Д.
Country: United State
Date: 28.08.2018
Time: 6:16
Description: Package departed international carrier facility
Как вы можете видеть на оттисках, не все имеют свою страну. Знайте об этом!
К одному из ответов редакции:
['Sweden', '29.08.2018', '11:08', 'Package arrived at international carrier']
['United States', '28.08.2018', '6:16', 'Package departed international carrier facility']
['Edgewood,\t\t\t\t\t\t\t\n\n\t\t\t\t \n\t\t\t\t \t\n\t\t\t\t \tNY,\t\t\t\t \n\n\t\t\t\t \n\t\t\t\t \t\n\t\t\t\t \tUnited States', '27.08.2018', '20:00', 'Package transferred to post office']
['United States', '27.08.2018', '18:42', 'Package processed by international carrier']
['EDGEWOOD,\t\t\t\t\t\t\t\n\n\t\t\t\t \n\t\t\t\t \t\n\t\t\t\t \tNY,\t\t\t\t \n\n\t\t\t\t \n\t\t\t\t \t\n\t\t\t\t \tUnited States', '24.08.2018', '15:51', 'Package processed by UPS Mail Innovations origin facility']
['', '24.08.2018', '12:55', 'Package received for processing by UPS Mail Innovations']
['United States', '22.08.2018', '8:19', 'Shipment information received by UPS Mail Innovations']