python3でスクレイピングをしているのですがURL先のhtmlのコードを文字列として違う変数に格納しようとしているのですがstr()が使えません。エラーはこう表記されています。
python
1 st_r = str(link) 2TypeError: 'str' object is not callable
python
1#!usr/bin/env python 2# -*-coding:utf-8 -*- 3 4import urllib.request 5from bs4 import BeautifulSoup 6 7url = "http://news.yahoo.co.jp/" 8htmlfp = urllib.request.Request(url) 9htmlfp = urllib.request.urlopen(htmlfp) 10html = htmlfp.read().decode("utf-8", "replace") 11htmlfp.close() 12 13soup = BeautifulSoup(html) 14for link in soup.findAll("a"): 15 st_r = str(link) 16 judge = "http://news.yahoo.co.jp/pickup/" 17 if st_r.find(judge): 18 start = st_r.find(judge)-1 + len(judge) 19 end = start + 6 20 get_url = judge + st_r[start:end] 21 print (get_url)
strを変数に使ってないのにエラーがでて原因がよくわかりません。原因を教えて下さい。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/03 13:11