×
Community Blog Empower Your Web with Python

Empower Your Web with Python

In this article, you will get some information on the application of python for your DirectMail, Headless Web Scraping Bot and data analysis.

How to Apply API Gateway for DirectMail in Python

The Alibaba SDK for DirectMail does not support Python. It does support PHP, Java and C#. A very common use case for DirectMail is delivering emails for dynamic and static websites. For dynamic websites PHP is perfect. For static websites, integrating Function Compute with DirectMail is perfect. However, Function Compute does not support PHP. This means that you develop in one language on your desktop and another in the cloud.

In this article I will focus on the DirectMail REST API and include a real working example in Python.

Calculating the correct dates

# Correctly formatted date and time
now = datetime.datetime.utcnow()

# Date used by the HTTP "Date" header
date = now.strftime("%a, %d %b %Y %H:%M:%S GMT")

# Date used by the API parameter "Timestamp"
utc = now.isoformat(timespec='seconds') + 'Z'

How to Write a Headless Web Scraping Bot in Python

In this article, you will get some information on writing our own basic headless web scraping "bot" in Python with Beautiful Soup 4 on an Alibaba Cloud Elastic Compute Service (ECS) instance with CentOS 7.

Install our Python Packages through Pip

Now we need to install our Python packages we will be using today, Requests and Beautiful Soup 4.

We will install these through PIP.

pip36u install requests
pip36u install beautifulsoup4

Requests is a Python module that allows us to navigate to a web page with the Requests .get method.

Requests allows you to send HTTP/1.1 requests, all programatically through the Python script. There's no need to manually add query strings to your URLs, or to form-encode your POST data. Keep-alive and HTTP connection pooling are 100% automatic. We will be focusing on the Requests .get method today to grab a web page source.

Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree.

We will be using Beautiful Soup 4 with the standard html.parser in Python to parse and organize the data from the web page source we will be getting with Requests. In this tutorial we will use the Beautiful Soup "prettify" method to organize our data in a more human readable way.

Lets make a folder called "Python_apps". Then, we will change our present working directory to Python_apps.

mkdir Python_apps
cd Python_apps

Data Analysis: FlashTex or RegEx

In this article, we will discuss how you can use FlashText, a python library that is 100 times faster than RegEx to perform data analysis.

Before you proceed with your analysis, you need to clean your source data, even for the simplest text. This often includes searching and replacing keywords. For example, search the corpus for the keyword "Python," or replace all "python" to "Python."

The Smarter and Faster way of Data Cleansing - FlashText

As the name suggests, FlashText is one of the fastest ways to execute search and replace keywords. It is an open source python library on GitHub.

When using FlashText, begin by providing a list of keywords. FlashText uses this list to build an internal Trie dictionary. You then send it a string of text depending on whether you want to search or replace.

Related Blog Posts

Alibaba Cloud DevOps Cookbook Part 3 – Function Compute with Python 3.0

In today's article we will be exploring Alibaba Cloud Function Compute for DevOps with some example programs using Python 3. Our ultimate goal is to combine API Gateway, Function Compute, and Direct Mail to provide a contact form suitable for a static website hosted on OSS.

Related Market Product

AISE TensorFlow 1.9 Python 3.6 CPU MKL Notebook

A pre-configured and fully integrated minimal runtime environment with TensorFlow, an open source software library for machine learning, Keras, an open source neural network library, Jupyter Notebook, a browser-based interactive notebook for programming, mathematics, and data science, and the Python programming language. The stack is built with the Intel MKL and MKL-DNN libraries and optimized for running on CPU.

Versions: TensorFlow 1.8.0, Python 3.6.3, Development preset 1, Libc 2.22, OpenBLAS 0.2.20, Python_enum34 1.1.6, NumPy 1.13.3, Ubuntu 16.04

Related Documentation

Python SDK Developer Guide: Use CommonRequest

If an Alibaba Cloud product does not provide an SDK for its APIs, you can use the generic calling method (CommonRequest) to call the product APIs. By using the CommonRequest calling method, you can call any API.

Python SDK Developer Guide: Handle errors

Alibaba Cloud Python SDK returns corresponding exceptions when an error occurs on the service side or the SDK side. These exceptions contain detailed error information, including the error code (ErrCode) and error message (ErrMsg).

You do not need to handle these returned errors. You only need to make corresponding modifications based on the error message.

Related Products

Direct Mail

DirectMail is a simple and efficient service to send email notifications and batch email quickly and efficiently without the need to build your own email server. DirectMail is a key product for serving Alibaba's own e-commerce platforms, which includes servicing Alibaba's record-breaking annual sales festival. Tens of millions of emails are sent every day through DirectMail by Alibaba and Alibaba Cloud customers.

DataV

DataV is a powerful yet accessible data visualization tool, featuring geographic information systems allowing for rapid interpretation of data to understand relationships, patterns, and trends. All packed into a user-friendly interface.

By integrating live dashboards, DataV can present and monitor business data simultaneously. This data-driven approach enables for well-organized data mining and analysis allowing the user to seize new opportunities that otherwise might remain hidden.

Related Course

Data Visualization Using Python

Data visualization capabilities are very important. A beautiful and clear charts can help you understand the data intuitively when you explore and analyze data, Data visualization also plays an important role in your interactions with customers, and it helps you communicate the quantitative characteristics of the data. From this perspective, making an eye-catching chart is an indispensable technology.

This training introduces the basic concepts of Python visualization, and the basic python visualization library Matplotlib as well as the two important third-party libraries based on matplotlib: pandas and seaborn. The training also introduces how to use Python visualization library for data analysis and processing.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 763 followers

You may also like

Comments