如何安装Mechanize for Python

如何安装Mechanize for Python

在这篇文章中,我们将为Python安装Mechanize。Mechanize是由John J. Lee设计的,2017年由Kovid Goyal接手维护。它遵循Python中的有状态程序化网络浏览

Mechanize模块的特点

  • Mechanize浏览器实现了urllib2.OpenerDirector的接口。
  • 它具有HTML表单填充的功能/方法
  • 轻松追踪 浏览器历史记录
  • 自动处理HTTP-Equiv和刷新
  • 获得的链接解析
  • urllib2函数存在于mechanize中。

安装

在Windows上

PIP是一个软件包管理系统,用于安装和管理用Python编写的软件包/库。这些文件存储在一个被称为Python Package Index (PyPI)的大型 “在线存储库 “中。如果PIP不存在,请查看如何在Windows上安装PIP? 并按照所提供的指示操作。

Mechanize可以直接下载并使用pip(软件包管理器)进行安装。要安装Mechanize,只需在命令行中输入以下命令。

pip install mechanize

如何安装Mechanize for Python

在Linux上

你可以在Linux中使用pip和apt-get命令来安装machineryize。要使用pip安装,在终端键入以下命令。

pip3 install mechanize

要使用apt安装,在终端键入以下命令。

sudo apt-get install python-mechanize

从Github安装

要从github上安装,我们需要将该 repo 克隆到我们的系统中。要克隆回购,然后安装它,在终端键入以下命令。

git clone https://github.com/python-mechanize/mechanize.git
cd mechanize
pip3 install -e

示例

mechanize使用 mechanize.urlopen() 方法导出完整的接口。

# import module
import mechanize
 
# read url with urlopen()
response = mechanize.urlopen("http://www.geeksforgeeks.com/")
print(response.read())

输出:

如何安装Mechanize for Python

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

软件安装教程