Html 美化组-在结果集上添加属性
以下是我的html结构:Html 美化组-在结果集上添加属性,html,python-3.x,web-scraping,beautifulsoup,Html,Python 3.x,Web Scraping,Beautifulsoup,以下是我的html结构: <div class='schedule-lists'> <ul> <li>...</li> <ul> <li>...</li> <ul class='showtime-lists'> <li>..
<div class='schedule-lists'>
<ul>
<li>...</li>
<ul>
<li>...</li>
<ul class='showtime-lists'>
<li>...</li>
<li><a auditype="N" cinema="0100" href="javascript:void(0);" >12:45</a></li>
<li>...</li> -- (same structured as above)
<li>...</li> -- (same structured as above)
<li>...</li> -- (same structured as above)
<li>...</li> -- (same structured as above)
- …
--(结构同上)
- …
--(结构同上)
- …
--(结构同上)
- …
--(结构同上)
这是我的密码:
from requests import get
from bs4 import BeautifulSoup
response = get('www.example.com')
response_html = BeautifulSoup(response.text, 'html.parser')
containers = response_html.find_all('ul', class_='showtime-lists')
#print(containers)
[<ul class="showtime-lists">
<li><a auditype="N" cinema="0100" href="javascript:void(0);" >12:45</a></li>
从请求导入获取
从bs4导入BeautifulSoup
response=get('www.example.com')
response\u html=BeautifulSoup(response.text'html.parser')
containers=response\u html.find\u all('ul',class='showtime-list')
#印刷品(容器)
[
如何在我的Resultset容器中添加属性?例如添加movietitle=“Logan”,使其成为:
<li><a movietitle="Logan" auditype="N" cinema="0100" href="javascript:void(0);" >12:45</a></li>
我的最佳尝试是使用.append方法,但可以这样做,因为结果集的作用类似于字典您可以尝试以下方法:
...
a = find_all('a')
i = 0
for tag in a:
a[i]['movietitle'] = 'Logan'
i += 1
print str(a)