为Qemu aarch32添加BeautifulSoup4模块
环境
概述
正文
#!/usr/bin/env python3 from urllib.request import urlopen
html = urlopen("http://www.pythonscraping.com/pages/page1.html");
print(html.read())
#!/usr/bin/env python2 from urllib2 import urlopen
html = urlopen("http://www.pythonscraping.com/pages/page1.html");
print(html.read())
[root@vexpress ~]# ./net.py3
b'<html>\n<head>\n<title>A Useful Page</title>\n</head>\n<body>\n<h1>An Interesting Title</h1>\n<div>\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\n</div>\n</body>\n</html>\n'
[root@vexpress ~]#
[root@vexpress ~]# ./net.py2
<html>
<head>
<title>A Useful Page</title>
</head>
<body>
<h1>An Interesting Title</h1>
<div>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</div>
</body>
</html>
其实Python提供了一个工具2to3,将Python2版本的代码转换为Python3版本, 我们在板子上面试试。
[root@vexpress ~]# 2to3 net.py2
-/bin/sh: 2to3: not found
[root@vexpress ~]# which 2to3
/usr/bin/2to3
#!/home/pengdonglin/src/qemu/python_cross_compile/Python2/aarch32/bin/python2.7 import sys
from lib2to3.main import main
sys.exit(main("lib2to3.fixes"))
问题出在第一行, 修改如下:
#!/usr/bin/env python2 import sys
from lib2to3.main import main
sys.exit(main("lib2to3.fixes"))
[root@vexpress ~]# 2to3 net.py2
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored net.py2
--- net.py2 (original)
+++ net.py2 (refactored)
@@ -, +, @@
#!/usr/bin/env python2 -from urllib2 import urlopen
+from urllib.request import urlopen html = urlopen("http://www.pythonscraping.com/pages/page1.html"); -print(html.read())
+print((html.read()))
RefactoringTool: Files that need to be modified:
RefactoringTool: net.py2
可以看到以+开始的行就是对应Python3版本的,使用下面的命令会将自动将转换后的文件存储下来:
[root@vexpress ~]# 2to3 net.py2 -w -n -o /tmp/
lib2to3.main: Output in '/tmp/' will mirror the input directory '' layout.
RefactoringTool: Skipping optional fixer: buffer
RefactoringTool: Skipping optional fixer: idioms
RefactoringTool: Skipping optional fixer: set_literal
RefactoringTool: Skipping optional fixer: ws_comma
RefactoringTool: Refactored net.py2
--- net.py2 (original)
+++ net.py2 (refactored)
@@ -, +, @@
#!/usr/bin/env python2 -from urllib2 import urlopen
+from urllib.request import urlopen html = urlopen("http://www.pythonscraping.com/pages/page1.html"); RefactoringTool: Writing converted net.py2 to /tmp/net.py2.
RefactoringTool: Files that were modified:
RefactoringTool: net.py2
可以看到/tmp/net.py2对应的就是Python3版本的:
[root@vexpress ~]# cat /tmp/net.py2 #!/usr/bin/env python2
from urllib.request import urlopen
html = urlopen("http://www.pythonscraping.com/pages/page1.html");
print((html.read()))
sudo apt-get install python-pip
sudo apt-get install python3-pip
sudo apt-get install python-bs4
sudo pip install beautifulsoup4
sudo pip3 install beautifulsoup4
$ls /usr/lib/python2./dist-packages/bs4
builder/ dammit.py dammit.pyc diagnose.py diagnose.pyc element.py element.pyc __init__.py __init__.pyc testing.py testing.pyc tests/
$ls /usr/lib/python3/dist-packages/bs4/
builder/ dammit.py diagnose.py element.py __init__.py __pycache__/ testing.py tests/
$cp /usr/lib/python2./dist-packages/bs4 /nfsroot/bs4_python2 -raf
$cp /usr/lib/python3/dist-packages/bs4 /nfsroot/bs4_python3 -raf
$tar -xf beautifulsoup4-4.5..tar.gz
$ls beautifulsoup4-4.5.
AUTHORS.txt beautifulsoup4.egg-info/ bs4/ convert-py3k* COPYING.txt doc/ doc.zh/ MANIFEST.in NEWS.txt PKG-INFO README.txt scripts/ setup.cfg setup.py test-all-versions* TODO.txt
cd beautifulsoup4-4.5./
./convert-py3k
在目录py3k下面的bs4就是用于Python3的,我们可以将这两个bs4分别拷贝到共享目录下:
$cp -raf bs4 /nfsroot/bs4_python2
$cp -raf py3k/bs4 /nfsroot/bs4_python3
sudo cp -raf bs4 /usr/local/lib/python2./site-packages/
sudo cp -raf py3k/bs4 /usr/local/lib/python3./site-packages/
[root@vexpress ~]# mount -t nfs -o nolock 192.168.1.100:/nfsroot /mnt
[root@vexpress ~]# cp -raf /mnt/bs4_python2 /usr/lib/python2./site-packages/bs4
[root@vexpress ~]# cp -raf /mnt/bs4_python3/ /usr/lib/python3./site-packages/bs4
[root@vexpress ~]# python2
Python 2.7. (default, Mar , ::)
[GCC 4.8. (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
>>>
[root@vexpress ~]# python3
Python 3.6. (default, Mar , ::)
[GCC 4.8. (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
>>>
如果导入的时候没有报错,表示一切正常。
#!/usr/bin/env python3 from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read(), "html.parser")
print(bsObj.h1)
#!/usr/bin/env python2 from urllib2 import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.pythonscraping.com/pages/page1.html")
bsObj = BeautifulSoup(html.read(), "html.parser")
print(bsObj.h1)
[root@vexpress ~]# ./bs4.py3
<h1>An Interesting Title</h1>
[root@vexpress ~]# ./bs4.py2
<h1>An Interesting Title</h1>
为Qemu aarch32添加BeautifulSoup4模块的更多相关文章
- python---requests和beautifulsoup4模块的使用
Requests:是使用 Apache2 Licensed 许可证的 基于Python开发的HTTP 库,其在Python内置模块的基础上进行了高度的封装,从而使得Pythoner进行网络请求时,变得 ...
- nginx添加 nginx_heath模块
原因?为什么会使用nginx_heath 这个模块,主要是如nginx+tomcat部署的时,tomcat挂了之后nginx->upstream 轮询是可以踢掉挂掉的tomcat服务的,如果部署 ...
- 使用pip安装BeautifulSoup4模块
1.测试是否安装了BeautifulSoup4模块 import bs4 print bs4 执行报错说明没有安装该模块 Traceback (most recent call last): File ...
- nginx 添加nginx-http-concat模块
github地址:https://github.com/alibaba/nginx-http-concat/tree/master 简单的描述一下吧,网上说的安装新的模块需要重新编译nginx,具体的 ...
- 嵌入式linux驱动开发之给linux系统添加温度传感器模块
忙了几天,终于可以让ds18b20在自己的开发板的linux系统上跑了!虽然ds18b20不是什么新鲜玩意,但是想想知己可以给linux系统添加模块了还是有点小鸡冻呢! 虽然说现在硬件的资源非常丰富而 ...
- 动态编译添加php模块
注意:转载请注明出处:http://www.programfish.com/blog/?p=85 在很多时候我们用linux里搭建web服务器的时候会需要编译安装php套件,而在编译安装后可能又会需要 ...
- httpd添加新模块
*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...
- yum安装的Nginx添加第三方模块支持tcp
需求:生产有个接口是通过socket通信.nginx1.9开始支持tcp层的转发,通过stream实现的,而socket也是基于tcp通信. 实现方法:Centos7.2下yum直接安装的nginx, ...
- nginx 番外----添加第三方模块
#第三方模块需要先进行下载,然后再编译时指定文件目录 1.查看当前编译模块 root@nginx sbin]# ./nginx -V #查看当前添加模块 nginx version: nginx/ b ...
随机推荐
- spring各个版本源码
各版本源码下载地址 http://maven.springframework.org/release/org/springframework/spring/
- /dev/null和/dev/zero的区别
/dev/null,外号叫无底洞,你可以向它输出任何数据,它通吃,并且不会撑着!/dev/zero,是一个输入设备,你可你用它来初始化文件. /dev/null------它是空设备,也称为位桶(bi ...
- 什么叫“回归”——“回归”名词的由来&&回归与拟合、分类的区别 && 回归分析
http://blog.csdn.net/denghecsdn/article/details/77334160
- 前端架构之路:Windows下安装Nodejs步骤
最近打算把我们的微信端用Vue.js重构,为什么选择Vue.js,一是之前使用的是传统的asp.net mvc,多页面应用用户体验比单页面要差.二是使用过Angular.js,感觉对开发人员要求较 ...
- HTML5 标签语法变化和使用概念
1.H5与H4的区别 概念的变化: H5更注重内容与结构,不再只专注于表现. 声明与标签: 新的声明背简化: <!DOCTYPE html> <meta charset=utf-8& ...
- 详解VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射
本文以VirtualBox为例 如果出现主机无法ping通虚拟机的情况,请首先确认虚拟机防火墙已关闭. 一.NAT模式 特点: 1.如果主机可以上网,虚拟机可以上网 2.虚拟机之间不能ping通 3. ...
- 通过css属性hack完成select样式美化,并兼容IE
最近在重构时遇到了select样式问题,并且需要在不影响语义化的情况下,兼容IE8. 经过一番的百度后始终没有找到合适的纯CSS解决方案,最后换了一下思路,大胆使用了属性hack: 在chrome和F ...
- 《Population Based Training of Neural Networks》论文解读
很早之前看到这篇文章的时候,觉得这篇文章的思想很朴素,没有让人眼前一亮的东西就没有太在意.之后读到很多Multi-Agent或者并行训练的文章,都会提到这个算法,比如第一视角多人游戏(Quake ...
- RabbitMQ for windows
一.搭建环境 Rabbit MQ 是建立在强大的Erlang OTP平台上,因此安装RabbitMQ之前要先安装Erlang. erlang:http://www.erlang.org/downloa ...
- [ 转载 ] get和post的区别
GET和POST两种基本请求方法的区别 GET和POST是HTTP请求的两种基本方法,要说它们的区别,接触过WEB开发的人都能说出一二. 最直观的区别就是GET把参数包含在URL中,POST通过r ...