Python中文
首页
教程
问答
标签
搜索
登录
注册
python在美化我的html?
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>据我所知,我有两台机器,分别运行python2.5和beautifulsoup3.1.0.1。在</p> <p>我正在尝试刮<a href="http://utahcritseries.com/RawResults.aspx" rel="nofollow noreferrer">http://utahcritseries.com/RawResults.aspx</a>,使用:</p> <pre><code>from BeautifulSoup import BeautifulSoup import urllib2 base_url = "http://www.utahcritseries.com/RawResults.aspx" data=urllib2.urlopen(base_url) soup=BeautifulSoup(data) i = 0 table=soup.find("table",id='ctl00_ContentPlaceHolder1_gridEvents') #table=soup.table print "begin table" for row in table.findAll('tr')[1:10]: i=i + 1 col = row.findAll('td') date = col[0].string event = col[1].a.string confirmed = col[2].string print '%s - %s' % (date, event) print "end table" print "%s rows processed" % i </code></pre> <p>在我的windows机器上,我得到了正确的结果,即日期和事件名称的列表。在我的mac上,我没有。相反,我得到</p> ^{pr2}$ <p>我注意到当我</p> <pre><code>print row </code></pre> <p>在我的windows机器上,tr数据看起来与源html完全相同。请注意第二行表格上的样式标记。前两排是:</p> <pre><code><tr> <td> 3/2/2002 </td> <td> <a href="Event.aspx?id=226"> Rocky Mtn Raceway Criterium </a> </td> <td> Confirmed </td> <td> <a href="Event.aspx?id=226"> Points </a> </td> <td> <a disabled="disabled"> Results </a> </td> </tr> <tr style="color:#333333;background-color:#EFEFEF;"> <td> 3/16/2002 </td> <td> <a href="Event.aspx?id=227"> Rocky Mtn Raceway Criterium </a> </td> <td> Confirmed </td> <td> <a href="Event.aspx?id=227"> Points </a> </td> <td> <a disabled="disabled"> Results </a> </td> </tr> </code></pre> <p>在我的mac上,当我打印前两行时,样式信息从tr标记中删除,并移动到每个td字段中。我不明白为什么会这样。我没有得到任何其他日期值,因为BeautifulSoup每隔一个日期就会有一个字体标签。以下是mac的输出:</p> <pre><code><tr> <td> 3/2/2002 </td> <td> <a href="Event.aspx?id=226"> Rocky Mtn Raceway Criterium </a> </td> <td> Confirmed </td> <td> <a href="Event.aspx?id=226"> Points </a> </td> <td> <a disabled="disabled"> Results </a> </td> </tr> <tr bgcolor="#EFEFEF"> <td> <font color="#333333"> 3/16/2002 </font> </td> <td> <font color="#333333"> <a href="Event.aspx?id=227"> Rocky Mtn Raceway Criterium </a> </font> </td> <td> <font color="#333333"> Confirmed </font> </td> <td> <font color="#333333"> <a href="Event.aspx?id=227"> Points </a> </font> </td> <td> <font color="#333333"> <a disabled="disabled"> Results </a> </font> </td> </tr> </code></pre> <p>我的脚本在windows下显示正确的结果我需要做什么才能让我的Mac正常工作?在</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>beauthoulsoup的3.1版有<a href="http://www.crummy.com/software/BeautifulSoup/3.1-problems.html" rel="nofollow noreferrer">documented problems</a>。在</p> <p>您可能需要再次检查您实际使用的版本,如果是,则降级。在</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
python语法错误(如果不在Z中,则在X中表示s)
8 回答
Python语法错误(无效)概率
8 回答
python语法错误*带有可选参数的args
6 回答
python语法错误2.5版有什么办法解决吗?
9 回答
Python语法错误2.7.4
10 回答
python语法错误30/09/2013
2 回答
Python语法错误E001
10 回答
Python语法错误not()op
7 回答
python语法错误outpu
8 回答
Python语法错误print len()
3 回答
python语法错误w3
5 回答
Python语法错误不是caugh
4 回答
python语法错误及yt-packag的使用
3 回答
python语法错误可以查出来!!瓦里亚布
7 回答
Python语法错误可能是缩进?
1 回答
Python语法错误和缩进
10 回答
Python语法错误在while循环中生成随机numb
8 回答
Python语法错误在哪里?
5 回答
python语法错误在尝试导入包时,但仅在远程运行时
8 回答
Python语法错误在电子邮件地址提取脚本中
6 回答