2015-04-23 37 views
0

嗨我想從多個網站rss提取圖像。解析rss不同標籤提取圖像

首先RSS

<enclosure type="image/jpeg" length="321742" url="http://www.sitio.com.uy//uploads/2014/10/19/54441d68e01af.jpg"/> 

二RSS

<g:image_link>http://img.sitio2.com/imagenes/314165_20150422201743_635653477836873822w.jpg</g:image_link> 

需要提取圖像的URL。

我的代碼是Beatifulsoup在python

response = requests.get(url) 
    soup = bs4.BeautifulSoup(response.text) 

    items = soup.find_all('item') 

    for item in items: 
     title = item.find('title').get_text().encode('utf-8') 
     description = item.find('description').get_text().encode('utf-8') 
     category = item.find('category').get_text().encode('utf-8') 
     image = item.find('enclosure') 

     print(image) 
+0

而且,怎麼了? –

+0

非功能g:image_link – user3058963

回答

0

您可以搜索使用標籤列表多個標籤。

item.find(['enclosure', 'g:image_link']) 

這將返回找到的第一個標籤。如果有多個標籤使用find_all

item.find_all(['enclosure', 'g:image_link']) 
+0

非常感謝 – user3058963

+0

我該如何提取url和輸入圖像? – user3058963