Reputation: 221
How to get the content of a div with class using web scraping?
I cannot fetch details of a single div
with a class name.
import mechanize
import re
import logging
from BeautifulSoup import BeautifulSoup
br = mechanize.Browser()
br.set_handle_equiv(False)
url = "https://www.abcd.com"
ua = 'Mozilla/5.0 (X11; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 (compatible;)'
br.addheaders = [('User-Agent', ua), ('Accept', '*/*')]
br.set_debug_http(True)
logging.getLogger('mechanize').setLevel(logging.DEBUG)
html = br.open(url)
soup = BeautifulSoup(html)
for i in soup.findAll('div', 'className'):
print i
Upvotes: 1
Views: 2949
Reputation: 67
------top code-----
html = br.open(url)
soup = BeautifulSoup(html)
for i in soup.findAll('div', {"class":"NAME_OF_CLASS"})
print i
This should help you.
Upvotes: 1
Reputation: 156
You can use like this
soup.findAll('div', {'attribute-name': 'attribute-value'})
For example:
soup.findAll('div', {'class': 'class-name'})
Upvotes: 4