i am trying geting urls from li tag but getting only one li instead of all, i tried all beautifulsoup and lxml, html parser.
i want all images from li in div class="viewport" in url given below
my code is as bellow...
from lxml import html
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding': 'none',
'Accept-Language': 'en-US,en;q=0.8',
'Connection': 'keep-alive'}
doc = html.parse(url)
rows = doc.xpath('//div[@class="viewport"]//ul/li/img')
for row in rows:
print(row.attrib['src'], row.text_content())
i also tried using Beutifulsoup method as below
req = urllib2.Request(url, headers=hdr)
content = urllib2.urlopen(req)
soup = BeautifulSoup(content, "lxml")
ul = soup.find("ul", class_='plist')
li = ul.find_all('li')
for l in li:
img = l.img['src']
but getting onlyy one image src instead of all.