安卓手机上运行Python爬虫
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1. 安装Termux</span></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在软件市场搜索下载安装<span style="color: black;">就可</span>, 这个软件<span style="color: black;">能够</span>让你把手机当Linux电脑<span style="color: black;">运用</span>, 除了屏幕小点儿.</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">为了敲命令方便, <span style="color: black;">意见</span>安装输入法: CodeBoard, 功能键几乎都有了</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">参考自 安卓手机运行python程序的软件:Termux</p>注: py是<span style="color: black;">由于</span>用了别名 alias py=‘python’
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2. 安装环境</span></h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">私信<span style="color: black;">博主</span>01<span style="color: black;">就可</span>获取<span style="color: black;">海量</span>Python学习资料</span></strong></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2.1 安装Python</span></h1> <span style="color: black;">p<span style="color: black;">公斤</span></span> <span style="color: black;">update</span>
<span style="color: black;">p<span style="color: black;">公斤</span></span> <span style="color: black;">upgrade </span>
<span style="color: black;">apt</span> <span style="color: black;">update </span>
<span style="color: black;">apt</span> <span style="color: black;">upgrade</span>
<span style="color: black;">apt</span> <span style="color: black;">install python</span>
<span style="color: black;">pip</span> <span style="color: black;">install bs4 requests </span>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2.2 安装lxml</span></h1> <span style="color: black;">apt</span> <span style="color: black;">install clang </span>
<span style="color: black;">apt</span> <span style="color: black;">install libxml2 libxml2-dev libxslt libxslt-dev</span>
<span style="color: black;">pip</span> <span style="color: black;">install lxml </span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">倘若</span>遇到报错 Python.h not found 就执行 apt install python-dev</span></span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">下载对应脚本</span></h1> <span style="color: black;">apt</span> <span style="color: black;">install git </span>
<span style="color: black;">git</span> <span style="color: black;">clone https://github.com/Kuangcp/PythonLearn.git</span>
<span style="color: black;">cd</span> <span style="color: black;">PythonLearn/learning/Spider/scrpy_learn/55156</span>
配置好一个用来存URL的redis数据库<span style="color: black;">能够</span>是自己远程服务器上<span style="color: black;">亦</span><span style="color: black;">能够</span>是本地 <span style="color: black;"><span style="color: black;">apt install redis</span></span>执行<span style="color: black;"><span style="color: black;">redis-server</span></span><span style="color: black;">就可</span>开启服务<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运行这两个脚本前先确定redis以及下载目录配置正确, <span style="color: black;">仅有</span>这两个是<span style="color: black;">必须</span>配置的</span></p><span style="color: black;"><span style="color: black;">而后</span>就<span style="color: black;">能够</span>直接 </span><span style="color: black;"><span style="color: black;">py simple.py</span></span> <span style="color: black;">或</span>先 <span style="color: black;"><span style="color: black;">py simple.py -h</span></span> 先看一下参数说明就会提示 <span style="color: black;">初始</span>爬取的URL, 例如 <span style="color: black;"><span style="color: black;">http://www.55156.com/gaoqingtaotu/xiuren/204409_22.html</span></span>就<span style="color: black;">起始</span>爬取URL了<span style="color: black;">打开 同目录下 的 download.py 配置好下载目录 <span style="color: black;">而后</span></span><span style="color: black;"><span style="color: black;">py download.py</span></span>, <span style="color: black;">或</span>直接 py download.py `<span style="color: black;">pwd</span>`
就在脚本旁的目录下<span style="color: black;">一直</span>的下载<span style="color: black;">照片</span>了<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">为了<span style="color: black;">运用</span>方便, <span style="color: black;">意见</span>配置别名</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">vi ~/.bashrc</span></span></p> <span style="color: black;">alias</span>py=<span style="color: black;">python</span>
<span style="color: black;">alias</span> img=<span style="color: black;">py simple_path </span> <span style="color: black;"># 替换为simple绝对路径</span>
<span style="color: black;">alias</span> down=<span style="color: black;">py download_path</span> <span style="color: black;"># 替换为down绝对路径</span>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;"><span style="color: black;">或</span></span></span></p> <span style="color: black;">cd</span> 到脚本所在目录<span style="color: black;">而后</span>:
<span style="color: black;">echo</span> <span style="color: black;">"alias img=python `pwd`/simple.py "</span> >> ~/.bashrc
<span style="color: black;">echo</span> <span style="color: black;">"alias down=python `pwd`/download.py `pwd` "</span> >> ~/.bashrc
以后就只要<span style="color: black;">起步</span>termux<span style="color: black;"><span style="color: black;">img</span></span> 下载<span style="color: black;">照片</span>url<span style="color: black;"><span style="color: black;">down</span></span> 下载<span style="color: black;">照片</span>文件了<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">又<span style="color: black;">发掘</span>一个问题, <span style="color: black;">由于</span>这个软件的数据是在/data/data/目录下, 而这个目录<span style="color: black;">拜访</span>是要 root的, <span style="color: black;">因此</span></span><span style="color: black;">上诉</span><span style="color: black;">脚本生成别名后, 手动修改为安卓可<span style="color: black;">拜访</span>的目录<span style="color: black;">就可</span></span></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">我的手机是 /storge/emulate/0/ <span style="color: black;">便是</span>存储的根目录</span></p>
论坛外链网http://www.fok120.com/ 外贸B2B平台有哪些? 我深受你的启发,你的话语是我前进的动力。 你的见解独到,让我受益匪浅,非常感谢。 这篇文章真的让我受益匪浅,外链发布感谢分享! 请问、你好、求解、谁知道等。 交流如星光璀璨,点亮思想夜空。
页:
[1]