Python的刮(美丽的汤),从这个HTML获取数据 [英] Python scraping (Beautiful Soup) to obtain data from this HTML
本文介绍了Python的刮(美丽的汤),从这个HTML获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<ul>
<li>
<div class="c_logo_box">
<a href="money-transfer-companies/ria-money-transfer/"><img src="http://www.compareremit.com/uploads/ria-logo11.png" style="height:57px;width:147px;" alt="RIA Money Transfer"></a>
<span class="rs"> <span class="txt13">₹</span> 61.24</span>
</div>
</li>
...
我想从'ALT =利雅汇款和率从跨度61.24报废的名称
I wish to scrap the name from 'alt = Ria Money Transfer' and rate from span 61.24.
到目前为止,我有这样的Python code:
So far I have this Python code:
#!/usr/bin/python
import requests
import re
from bs4 import BeautifulSoup
r = requests.get('http://www.compareremit.com')
data = r.text
soup = BeautifulSoup(data)
for rate in soup.find_all('li', re.compile('money')):
print rate.text
它给了我什么。有人能告诉我什么我缺少什么?另外,我有难以想像我的支持,寻找在for循环搜索哪一个元素,可以在一般阐明如何知道在这种情况下,指定为条件的循环?
It gives me nothing. Could someone tell me what am I missing? Also, I'm having trouble visualizing which element I'm support to look for in the for loop search, could you clarify in general how to know what to specify as a condition in for loop in such cases?
推荐答案
您code在逻辑上是不正确的。为此,您可以通过多种途径,试试这个code
Your code is logically not correct. You can do this in multiple ways, try this code
#!的/ usr / bin中/ Python的
#!/usr/bin/python
import requests
import re
from bs4 import BeautifulSoup
r = requests.get('http://www.compareremit.com')
data = r.text
soup = BeautifulSoup(data)
for rate in soup.find_all('div',{"class":"c_logo_box"}):
print rate.a.img['alt']
print rate.span.text
这篇关于Python的刮(美丽的汤),从这个HTML获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文