1
リクエストモジュールを使用して、azlyricsの曲の歌詞を取得するPythonスクリプトを書いていました。これは私が書いたスクリプトです:なぜこのPythonスクリプトの接続が拒否されましたか?
import requests, re
from bs4 import BeautifulSoup as bs
url = "http://search.azlyrics.com/search.php"
payload = {'q' : 'shape of you'}
r = requests.get(url, params = payload)
soup = bs(r.text,"html.parser")
try:
link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
link = link.replace('http', 'https')
print(link)
raw_data = requests.get(link)
except Exception as e:
print(e)
を私は述べ例外だ:私はおそらくあまりにも多くのリクエストを送信しようとしていますインターネット上で読む
Max retries exceeded with url: /lyrics/edsheeran/shapeofyou.html (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7fbda00b37f0>: Failed to establish a new connection: [Errno 111] Connection refused',))
を。だから私はスクリプトをしばらく寝かせました:
import requests, re
from bs4 import BeautifulSoup as bs
from time import sleep
url = "http://search.azlyrics.com/search.php"
payload = {'q' : 'shape of you'}
r = requests.get(url, params = payload)
soup = bs(r.text,"html.parser")
try:
link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
link = link.replace('http', 'https')
sleep(60)
print(link)
raw_data = requests.get(link)
except Exception as e:
print(e)
しかし運はありません!
は、だから私はimport requests, re
from bs4 import BeautifulSoup as bs
from time import sleep
from urllib.request import urlopen
url = "http://search.azlyrics.com/search.php"
payload = {'q' : 'shape of you'}
r = requests.get(url, params = payload)
soup = bs(r.text,"html.parser")
try:
link = soup.find('a', {'href':re.compile('http://www.azlyrics.com/lyrics/edsheeran/shapeofyou.html')})['href']
link = link.replace('http', 'https')
sleep(60)
print(link)
raw_data = urlopen(link).read()
except Exception as e:
print(e)
urllib.requestと同じことをしようとしたが、その後旨異なる例外だ:私はそれをどのように修正すればよいいただきましたそれと間違ってと
<urlopen error [Errno 111] Connection refused>
は、誰もが1を教えてもらえますか?
ありがとうございます。出来た。私はあなたの答えをアップアップすることができますが、今私は十分な評判を持っていません。 –
しかし、なぜそれは要求で動作していませんか? –
問題ありません。あなたは「要求を扱う」という意味はどういう意味ですか?あなたの評判で[受け入れられたとして回答をマークする](http://stackoverflow.com/help/someone-answers): –