私はPythonには新しく、サブディレクトリからリンクを取得するためにウェブサイトスクレーパーを作成しようとしています。後で別のクラスに渡して、imagureから画像を自動ダウンロードします。このコードスニペットでPythonリストオブジェクトに属性エラーがありません
、私はちょうどsubredditを読んでのhrefから任意のimagurのHTMLSをこすりしようとしていますが、私は次のエラーを取得する:
AttributeError: 'list' object has no attribute 'timeout'
任意のアイデアをこれが起こっかもしれない理由を?ここでは、コードは次のとおりです。あなたが関数を呼び出す方法で
from bs4 import BeautifulSoup
from urllib2 import urlopen
import sys
from urlparse import urljoin
def get_category_links(base_url):
url = base_url
html = urlopen(url)
soup = BeautifulSoup(html)
posts = soup('a',{'class':'title may-blank loggedin outbound'})
#get the links with the class "title may-blank "
#which is how reddit defines posts
for post in posts:
print post.contents[0]
#print the post's title
if post['href'][:4] =='http':
print post['href']
else:
print urljoin(url,post['href'])
#print the url.
#if the url is a relative url,
#print the absolute url.
get_category_links(sys.argv)
完全なトレースバックを送信するか、行番号を記述してください。 –
urlopenで '.read()'を使いましたか? –
トレースバックを含む完全なエラーメッセージを投稿してください。このエラーはコードによって直接発生するものではなく、使用しているライブラリの1つから来ています。 – kindall