Skip to content

Instantly share code, notes, and snippets.

@ijharulislam
Created April 29, 2015 15:22
Show Gist options
  • Save ijharulislam/0979d84662c2b6f7c177 to your computer and use it in GitHub Desktop.
Save ijharulislam/0979d84662c2b6f7c177 to your computer and use it in GitHub Desktop.
if __name__ == "__main__":
reload(sys)
sys.setdefaultencoding("utf-8")
import csv
import urllib2
import sys
from bs4 import BeautifulSoup
if __name__ == "__main__":
reload(sys)
sys.setdefaultencoding("utf-8")
page = urllib2.urlopen('http://www.att.com/shop/wireless/devices/smartphones.html').read()
soup = BeautifulSoup(page)
soup.prettify()
for anchor in soup.findAll('a', {"class": "clickStreamSingleItem"}):
print anchor['title']
with open('Smartphones.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',')
spamwriter.writerow([(anchor['title'])])
with open('Smartphones.csv', 'wb') as csvfile:
spamwriter = csv.writer(csvfile, delimiter=',')
for anchor in soup.findAll('a', {"class": "clickStreamSingleItem"}):
print anchor['title']
spamwriter.writerow([anchor['title'].encode('utf8')])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment