<div id="content-innerText">
<p>
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-51.jpg" title="" alt="" width="801" height="1200">
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-52.jpg" title="" alt="" width="1080" height="1616">
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-48.jpg" title="" alt="" width="682" height="1024">
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-49.jpg" title="" alt="" width="682" height="1024">
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-491.jpg" title="" alt="" width="682" height="1024">
<img src="http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-50.jpg" title="" alt="" width="682" height="1024">
</p>
</div>
- 爬取 img 标签中的 src 属性
elem = soup.find_all("div", {"id": "content-innerText"})
for i in elem[0].p.children:
print(i['src'])
for i in soup.find_all("div", {"id": "content-innerText"})[0].p.children:
print(i['src'])
- 结果:
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-51.jpg
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-52.jpg
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-48.jpg
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-49.jpg
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-491.jpg
http://222.186.150.182/wp-content/uploads/2016/02/2016-10-30_22-28-50.jpg