Код: Выделить всё
#Python code to scrape the shipment URLs
from bs4 import BeautifulSoup
import urllib.request
import urllib.error
import urllib
# read urls of websites from text file > change it to where you stock the file
list_open = open(r"C:\***\data.csv")
#skips the header
read_list = list_open.readlines()[1:]
file_path = "ShipmentUpdates.txt"
for url in read_list:
soup = BeautifulSoup(urllib.request.urlopen(url).read(), "html5lib")
# parse shipment info
shipment = soup.find_all("span")
Preparation = shipment[0]
Sent = shipment[1]
InTransit = shipment[2]
Delivered = shipment[3]
with open(file_path, "a") as f:
line= f"{url} ; Preparation {Preparation.getText()}; Sent {Sent.getText()}; InTransit {InTransit.getText()}; Delivered {Delivered.getText()}"
print (line)
f.write(line+'\n')
Код: Выделить всё
http://carmoov.fr/CfQd
; Preparation on 06/01/2022 at 17:45; Sent on 06/01/2022 at 18:14; InTransit ; Delivered on 07/01/2022 at 10:31
http://carmoov.fr/CfQz
; Preparation on 06/01/2022 at 11:18; Sent on 06/01/2022 at 18:14; InTransit ; Delivered on 07/01/2022 at 11:56
Не могли бы вы помочь проверить, в чем проблема?
Спасибо!
Подробнее здесь: https://stackoverflow.com/questions/707 ... -two-lines
Мобильная версия