Python(二十二)实现各大跨境船公司物流查询&CMA船司物流查询

一、前言

本章主要实现 【之前CMA船司物流信息查询】的遗留问题
Python(二十二)实现各大跨境船公司物流查询&CMA船司物流查询_第1张图片
解决思路

由于CMA船司查询需要进行[机器人验证]

方法1:直接从前端跳过,用selenium实现前端自动化,查询物流信息

方法2:捕捉到接口search,但需要将返回的前端页面进行解析,并提取出你需要的相关物流信息;

其他船司查询详细请看上篇blog.



二、代码实现

  • 我这里就直接用selenium进行UI自动化查询
  • 注意:需要提前下载和你浏览器相匹配版本的chormedrive,并将他放到python目录下(关于这part 我就不写了)
  • 下载地址: https://chromedriver.storage.googleapis.com/index.html
import time
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


class TestCmatest():
    def setup_method(self):
        """
        启动google浏览器
        :return:
        """
        chrome_options = Options()
        chrome_options.add_experimental_option("detach", True)  # 防止浏览器自动关闭
        self.driver = webdriver.Chrome(options=chrome_options)

    # def teardown_method(self, method):
    #     self.driver.quit()

    def test_cmatest(self, bill_number):
        """
        ui自动根据提单号查询
        :param bill_number:
        :return:
        """
        self.driver.get("https://www.cma-cgm.com/ebusiness/tracking")
        time.sleep(1)
        self.driver.find_element(By.ID, "Reference").click()
        time.sleep(1)
        self.driver.find_element(By.ID, "Reference").send_keys(bill_number)
        time.sleep(1)
        self.driver.find_element(By.ID, "btnTracking").click()
        time.sleep(1)
        # self.driver.execute_script("window.scrollTo(0,617)")


t = TestCmatest()
t.setup_method()
bill_number = "CAN0870714"
t.test_cmatest(bill_number)

你可能感兴趣的:(Python,python,开发语言)