L
L
lcd12322015-10-08 21:09:20
Python
lcd1232, 2015-10-08 21:09:20

BeautifulSoup not working?

Actually, I want to get the address of the picture. But the problem is that nothing works. Doesn't even show the document.

import urllib.request as urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen("http://www.vokrugsveta.ru/vs/").read()
soup = BeautifulSoup(page)
print(soup.find("img", class='framepic'))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2015-10-08
@lcd1232

import urllib.request as urllib2
from bs4 import BeautifulSoup
page = urllib2.urlopen("http://www.vokrugsveta.ru/vs/").read()
soup = BeautifulSoup(page)
imglink = soup.find("img", {"class": "framepic"}).get('src')
print (imglink)

boys use lxml instead of soup

A
Alexander, 2015-10-15
@Survtur

class - a reserved word of the language in Bs4 instead of it in the parameters, you can useclass_

# Варианты:
print(soup.find("img", class_='framepic'))
print(soup.find("img", {'class':'framepic'}))
print(soup.find("img", 'framepic'))

V
Vladimir Martyanov, 2015-10-08
@vilgeforce

print page покажет содержимое?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question