小编How*_*wli的帖子

用 BeautifulSoup 替换 python 中的文本

我正在尝试使用 beautifulSoup 解析表格并删除某些行中的空格 - so 而不是

<tr>
<td><small>15</small></td>
<td><small><small>Cat</small></small></td>
</tr>
<tr>
<td><small><small>   </small></small></td>
<td><small><small> </small></small></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我想要

<tr>
<td><small>15</small></td>
<td><small><small>Cat</small></small></td>
</tr>
<tr>
<td><small><small>-</small></small></td>
<td><small><small>-</small></small></td>
</tr>
Run Code Online (Sandbox Code Playgroud)

我设法做到了这一点:

from bs4 import BeautifulSoup

soup = BeautifulSoup (open("table.html"))

for a in soup.findAll('small'):
    a.replaceWith("-")
Run Code Online (Sandbox Code Playgroud)

这确实删除了空格,但它也删除了文本 15 和 cat (我知道我用什么替换了标签中的所有内容)。这是我所能得到的。如何修复该代码,以便它只会用 - 替换空格?

编辑:对不起,这是原始代码

<tr>
<td><small>15</small></td >
<td><small><small>&nbsp;</small></small></td >
</tr>
<tr>
<td><small><small>&nbsp; &nbsp;</small></small></td >
<td><small><small>&nbsp;</small></small></td >
</tr>
Run Code Online (Sandbox Code Playgroud)

beautifulsoup python-2.7

2
推荐指数
1
解决办法
8828
查看次数

Woocommerce变化产品价格显示默认值

我的商店设置了产品变体,目前在产品缩略图页面,即类别和过滤页面,它显示了一个(从£xx到£xx),当下到单个产品页面并且变化剃须被选择为变化价格显示.

我将某些属性设置为默认值,这是我希望在类别页面上显示的价格......标准尺寸和成本.但我不知道它是否可能或用什么代码来改变它.

在此输入图像描述 在此输入图像描述

这可能吗?有任何想法吗?

wordpress product woocommerce

1
推荐指数
1
解决办法
9989
查看次数

String.valueOf vs getString

getString和String.valueOf有什么区别?

在我的例子中,我在strings.xml中声明了"bgDefault": <string name="bgDefault">#0C090A</string>

我可以打印出这个值Log.d("xyz", R.color.bgDefault);也有效:getString(R.color.bgDefault)但为什么不起作用String.valueOf(R.color.bgDefault)呢?

android

0
推荐指数
1
解决办法
557
查看次数

WordPress - 无法登录

我正在更新WP并在jut中工作,然后突然无法登录或看到任何东西.这就是我得到的:[twitter]错误:PHP 5.3.0或更高版本要求

Warning: Cannot modify header information - headers already sent by (output started at /home2/keread/public_html/wp-content/plugins/twitter/widget_twitter_vjck.php:77) in /home2/keread/public_html/wp-login.php on line 415

Warning: Cannot modify header information - headers already sent by (output started at /home2/keread/public_html/wp-content/plugins/twitter/widget_twitter_vjck.php:77) in /home2/keread/public_html/wp-login.php on line 427

Warning: Cannot modify header information - headers already sent by (output started at /home2/keread/public_html/wp-content/plugins/twitter/widget_twitter_vjck.php:77) in /home2/keread/public_html/wp-includes/pluggable.php on line 678

Warning: Cannot modify header information - headers already sent by (output started at /home2/keread/public_html/wp-content/plugins/twitter/widget_twitter_vjck.php:77) in /home2/keread/public_html/wp-includes/pluggable.php on line 679

Warning: Cannot …
Run Code Online (Sandbox Code Playgroud)

wordpress

-1
推荐指数
1
解决办法
189
查看次数