python处理html的table标签
转载:http://www.xuebuyuan.com/583071.html
python处理html的table标签
import sys
import csv
import urllib2 import BeautifulSoup #page = urllib2.urlopen(sys.argv[1]).read()
soup = BeautifulSoup.BeautifulSoup(open(sys.argv[1]).read())
csvout = csv.writer(sys.stdout) for table in soup.findAll('table'):
print "<table border='1'>"
#print '#'
#print '# Table'
#print '# Fields: ' + ','.join([tr.text for tr in table.findAll('th')])
for row in table.findAll('tr'):
print "<tr>"
#csvout.writerow([tr.text for tr in row.findAll('td')])
for tr in row.findAll('td'):
print "<td>"
print tr.text.encode("utf-8")
print "</td>"
print "</tr>"
print "</table>"
break
#!/bin/bash #process.h basedir=$(dirname $1) echo $basedir #echo \<head\>\<meta http-equiv=\"Content-Type\" content=\"text/html\; charset=UTF-8\" /\>\</head\> >> $basedir/baobei.html prodname=$(grep -o '<title id="id_title">.*</title>' $1 | cut -d \> -f 2 | cut -d \< -f 1) prodname=$(echo $prodname | cut -d _ -f 1) price=$(grep -o '<span class="s1">[0-9]*</span>' $1 | cut -d \> -f 2 | cut -d \< -f 1) echo \<table\> > $basedir/baobei.html echo \<tr\> >> $basedir/baobei.html
echo \<td\>Name\</td\> >> $basedir/baobei.html
echo \<td\>$prodname\</td\> >> $basedir/baobei.html
echo \</tr\> >> $basedir/baobei.html echo \<tr\> >> $basedir/baobei.html
echo \<td\>Price\</td\> >> $basedir/baobei.html
echo \<td\>$price\</td\> >> $basedir/baobei.html
echo \</tr\> >> $basedir/baobei.html python ./printtab.py $1 >> $basedir/baobei.html echo \</table\> >> $basedir/baobei.html imgsrc=$(head -n 1 $basedir/imglist)
if test y$imgsrc = y; then
rm -rf $basedir/baobei.html && exit;
fi
echo \<img src=\'$imgsrc\'/\> >> $basedir/baobei.html cat $basedir/baobei.html | tr -d '\n' | tr -d '"' > $basedir/baobei.html.tmp
mv $basedir/baobei.html.tmp $basedir/baobei.html
#!/bn/bash #process2.sh basedir=$(dirname $1) name=$(grep -o "<td>Name</td><td>.*</td>" $1 | cut -d \> -f 4 | cut -d \< -f 1 ) if test "x$name" = "x" ; then
exit ;
fi price=$(grep -o "<td>Price</td><td>.*</td>" $1 | cut -d \> -f 4 | cut -d \< -f 1 ) if test "x$price" = "x" ; then
exit;
fi if test "x$class" = "x"
then
class=$(grep -o "<td>产品类型</td><td>.*</td>" $1 | cut -d \> -f 4 | cut -d \< -f 1 )
fi if test "x$class" = "x"
then
class=$(grep -o "<td>设备类型</td><td>.*</td>" $1 | cut -d \> -f 4 | cut -d \< -f 1 )
fi if test "x$class" = "x"
then
class=$(grep -o "<td>打印针数</td><td>.*</td>" $1 | cut -d \> -f 4 | cut -d \< -f 1 )
fi if test "x$class" = "x"
then
class="条形码打印机"
fi if $( echo $class | grep --quiet '票据' )
then
class="536187477"
elif $( echo $class | grep --quiet '发票' )
then
class="536187477"
elif $( echo $class | grep --quiet '票证' )
then
class="536187477"
elif $( echo $class | grep --quiet '存折' )
then
class="536187477" ##################################################################
elif $( echo $class | grep --quiet '针' )
then
class="536187477" ##################################################################
elif $( echo $class | grep --quiet '灯泡' )
then
class="536187479"
elif $( echo $class | grep --quiet 'UHE' )
then
class="536187479"
elif $( echo $class | grep --quiet 'UHP' )
then
class="536187479"
elif $( echo $class | grep --quiet 'HSCR' )
then
class="536187479" ###############################################################
elif $( echo $class | grep --quiet '条形码打印机' )
then
class="536187480" ##################################################################
elif $( echo $class | grep --quiet '证卡打印' )
then
class="536187483" ##################################################################
elif $( echo $class | grep --quiet '条码' )
then
class="536187481" elif $( echo $class | grep --quiet '扫描' )
then
class="536187481" elif $( echo $class | grep --quiet '阅读' )
then
class="536187481" elif $( echo $class | grep --quiet '采集' )
then
class="536187481" elif $( echo $class | grep --quiet '手持' )
then
class="536187481" elif $( echo $class | grep --quiet '数据终端' )
then
class="536187481" ##################################################################
elif $( echo $class | grep --quiet '激光' )
then
class="536187484" ##################################################################
elif $( echo $class | grep --quiet '喷墨' )
then
class="536187486" ##################################################################
elif $( echo $class | grep --quiet '复印' )
then
class="536187615" ##################################################################
elif $( echo $class | grep --quiet '一体机' )
then
class="536187485" ##################################################################
elif $( echo $class | grep --quiet '硒鼓' )
then
class="536187616" elif $( echo $class | grep --quiet '墨盒' )
then
class="536187616"
else
class="536187616"
fi ################################################################
imagepath=$(find $basedir -type f -iname "*.jpg")
if test "x$imagepath" = "x"; then
exit ;
fi
image=$(md5sum $imagepath | cut -d ' ' -f 1)
cp -rf $imagepath $basedir/../../template/$image.tbi
################################################################
desc=$(cat $1)
################################################################ echo -e \"$name\""\t"110514"\t"\",$class,\""\t"1"\t"\"上海\""\t"\"上海\""\t"\"b\""\t"$price"\t"0.000000"\t"1"\t"7"\t"2"\t"0.000000"\t"0.000000"\t"0.000000"\t""\t""\t"1"\t"1"\t"0"\t"1"\t"1"\t"0"\t"\"2012-10-16 13:09:48\""\t""\t"\"$desc\""\t""\t"\"20000:31140\;20196:3228846\;29969:107401\;30681:32998\;31468:102250\;31479:92188\;3415558:27513\;3415563:21959\;3415571:21959\;3415581:10122\;3415609:22041\;7884463:75957615\;14319244:80897641\;14319250:123483713\;14791484:10285019\;\""\t""\t""\t"0"\t"0"\t"\"2012-10-16 13:37:51\""\t"100"\t""\t"0"\t"\"$image:0:0:\|\;\""\t"\"\""\t"\"\""\t"\",\""\t"\",\""\t"\"\""\t"\"\""\t"0"\t"\"15758222730\""\t"15758222730
classtable = {
17 "536187477" : "票据打印机" ,
18 "536187478" : "针式打印机" ,
19 "536187479" : "投影灯泡" ,
20 "536187480" : "条形码打印机" ,
21 "536187481" : "条码设备" ,
22 "536187483" : "证卡打印机" ,
23 "536187484" : "激光打印机" ,
24 "536187485" : "多功能一体机" ,
25 "536187486" : "喷墨打印机" ,
26 "536187615" : "复印复合机" ,
27 "536187616" : "硒鼓" ,
28 }
python处理html的table标签的更多相关文章
- python 之 前端开发(form标签、单选框、多选框、file上传文件、按钮、label标签、下拉列表、textarea标签、fieldset标签、table标签)
11.25 form标签 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- img、列表和table标签
一.img图片 <body> <a href="https://www.fmtxt.com"> <img src="images/1.jpg ...
- ol,ul,dl,table标签的基本语法
ol,ul,dl,table标签的基本语法 有序列表: 无序列表: 自定义列表: <ol> <ul> < ...
- HTML——表格table标签,tr或者td
表格定义和用法 <tr> 标签定义 HTML 表格中的行. tr 元素包含一个或多个 th 或 td 元素. HTML 与 XHTML 之间的差异 在 HTML 4.01 中,tr 元素的 ...
- table标签
table标签使我们最常用的的标签,在使用table标签时我们要注意一些其属性,早期我们经常使用table标签对其进行页面布局但是现在我们基本不再使用,由此可见table标签也是非常强大的一个工具. ...
- dl标签和table标签
dl标签定义了一个定义列表 <html> <body> <h2>一个定义列表:</h2> <dl> <dt>计算机</ ...
- PHP自学4——通过函数将数组数据输出到html的Table标签中(使用函数的例子)
这一节其实说实话并没有什么干货,不过为了防止PO主的懒癌的复发,还是坚持放一点东西,即使是内容和长度都令人发指.这一节通过一个函数来实现将数组中的内容输出html的Table标签当中显示. 函数文件— ...
- PHP自学3——在html的<table>标签中显示用户提交表单
为了更好地显示用户提交表单,本节将在上一节的基础上将读取的用户表单显示在html的<table>标签中,这一节将用到和数组有关的知识. 本节代码将从外部文件(.txt文件)中读取信息于指定 ...
- display:table标签来自动改变列宽 改变的同时table的整体宽度跟随变化
发现公司里的所有分页功能都是通过display:talbe来实现的,但是用户最近说要让表格列宽可以拖动:所有我就寻找了好多的办法:网上找了很多的资料,但是都不是我要的效果因为他们都是列宽不改变要不就是 ...
随机推荐
- fileUpload1.HasFile的返回值永远都是false的问题处理
在aspnet项目中,如果有页面使用了fileupload,不巧你也在此页面使用了updatepanel局部刷新控件,那马就会出现一个很奇怪的问题:就是不管你选择文件了没有,fileUpload1.H ...
- centos下redis的安装
1.下载redis的安装包 http://download.redis.io/releases/redis-3.2.0.tar.gz 2.把安装包放到/opt/src/目录(看个人喜好)下 3.执行t ...
- FineUI第十六天---表格的排序和分页
表格的排序和分页 1.表格的排序需要: AllowSorting:是否允许排序. SortColumn:当前排序的列ID,当然也可以不设置此属性,而是在后台初始化代码中直接指定默认排序字段. Sort ...
- 简单实现div遮罩
顾名思义,div遮罩就是将网页上的一部分用div遮盖起来,防止用户误点,因此div遮罩的一个用途就是将table设置为不可编辑. 作者通过查找资料,并进行简单的测试,最终完成了以下几段简单代码,来实现 ...
- 第3次作业,c语言
<C语言程序设计>实验报告 学 号 160809201 姓 名 王浩然专业.班 计科16-2班 学 期 2016-2017 第1学期 指导教师 黄俊莲 ...
- javascript,检测对象中是否存在某个属性
检测对象中属性的存在与否可以通过几种方法来判断. 1.使用in关键字. 该方法可以判断对象的自有属性和继承来的属性是否存在. var o={x:1}; "x" in o; //tr ...
- vmware vcenter orchestrator configuration提示“用户名密码错误或登录失败超过次数被锁定”
首次登录,使用默认用户密码登录vmware/vmware vmware vcenter orchestrator configuration提示"用户名密码错误或登录失败超过次数被锁定&qu ...
- ajax给全局变量赋值问题解决
$.ajax({ type: "post", //以post方式与后台沟通 url: "./php/chartAjax.php", //与此php页面沟通 da ...
- Mysql5.7版本编译安装及配置
配置yum安装方式 1.配置本地yum源 vim /etc/yum.repos.d/rhel-source.repo [rhel-source] name=Red Hat Enterprise Lin ...
- Intellij IDEA使用总结
查询快捷键CTRL+N 查找类CTRL+SHIFT+N 查找文件CTRL+SHIFT+ALT+N 查 找类中的方法或变量CIRL+B 找变量的来源CTRL+ALT+B 找所有的子类CTRL ...