Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace urllib2 by requests #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions opengraph/opengraph.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# encoding: utf-8

import re
import urllib2
import requests
try:
from bs4 import BeautifulSoup
except ImportError:
Expand Down Expand Up @@ -47,8 +47,8 @@ def __getattr__(self, name):
def fetch(self, url):
"""
"""
raw = urllib2.urlopen(url)
html = raw.read()
raw = requests.get(url)
html = raw.text
return self.parser(html)

def parser(self, html):
Expand Down Expand Up @@ -123,4 +123,4 @@ def scrape_url(self, doc):
def scrape_description(self, doc):
tag = doc.html.head.findAll('meta', attrs={"name":"description"})
result = "".join([t['content'] for t in tag])
return result
return result
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
include_package_data=True,
zip_safe=False,
install_requires=[
'beautifulsoup4'
'beautifulsoup4',
'requests'
],
entry_points="""
# -*- Entry points: -*-
Expand Down