gpt4 book ai didi

python - BeautifulSoup错误消息?

转载 作者:行者123 更新时间:2023-12-03 08:50:15 26 4
gpt4 key购买 nike

我第一次使用BeautifulSoup。我看了一个youtube视频,模仿了他们的所作所为。我正试图从apt网站上获取租金价格,但我不断收到这样的消息:

Traceback (most recent call last):
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\rent.py", line 5, in <module>
sauce = urllib.request.urlopen("http://www.equityapartments.com/washington-dc/georgetown/2400-m-apartments##unit-availability-tile").read()
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 162, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 471, in open
response = meth(req, response)
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 581, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 509, in error
return self._call_chain(*args)
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 443, in _call_chain
result = func(*args)
File "C:\Users\Eun Hae Lee\AppData\Local\Programs\Python\Python35-32\lib\urllib\request.py", line 589, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400: Bad Request

此错误消息的原因是什么?

我使用的代码是
import urllib.request
import bs4 as bs

sauce = urllib.request.urlopen("http://www.equityapartments.com/washington-dc/georgetown/2400-m-apartments##unit-availability-tile").read()
soup = bs.beautifulsoup(sauce, 'html.parser')

print(soup)

感谢您的帮助!

最佳答案

此错误与BeautifulSoup无关-您从远程服务器的urlopen操作中得到400。您需要检查您的URL并确定为什么它不是合法的GET

关于python - BeautifulSoup错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42989690/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com