回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我对编码完全陌生。我试图创建一个程序来为我收集数据,但是当我编写代码打开url时,它显示HTTPError:HTTP Error 405:不允许我使用Python,我安装了Beautiful Soup,但是由于某种原因我得到了这个错误?我试过不同的标题,但没用。下面是代码。在</p>
<pre><code>from urllib.request import urlopen
from bs4 import BeautifulSoup
import urllib.request
import re
import numpy as np
# Opening the Builder website
html = "http://www.builderonline.com"
req = urllib.request.Request(html,headers={'User-Agent' : "Mozilla/5.0"})
soup = BeautifulSoup(urlopen(req).read(),"html.parser")
print ("end")
Error Messages:
Traceback (most recent call last):
File "test3.py", line 9, in <module>
soup = BeautifulSoup(urlopen(req).read(),"html.parser")
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 532, in open
response = meth(req, response)
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 642, in http_response
'http', request, response, code, msg, hdrs)
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 570, in error
return self._call_chain(*args)
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Users/NAGS/anaconda/lib/python3.6/urllib/request.py", line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Not Allowed
</code></pre>