【发布时间】:2020-04-08 05:09:32
【问题描述】:
我正在尝试获取一些带有漂亮汤的标签,以使用这些数据生成一个 bibtex 条目。
从浏览器访问 ISBN 巴西网站时,会显示有关该 ISBN 的信息。但是当我尝试使用 urlopen 和请求时,它给了我一个 HTTPError 代码 500。在浏览器中发生了这种情况,只能通过关闭选项卡并在另一个选项卡中打开相同的链接来解决。
网站要求提供验证码。我认为第一次搜索需要回答验证码,其他的,只需更改 url 中的 isbn 即可。
在此之后,当您点击“链接+isbn”时,它会显示有关该书的信息。我正在尝试使用这个“链接+isbn”来用美丽的汤进行网络抓取。
有效的链接:http://www.isbn.bn.br/website/consulta/cadastro/isbn/9788521208037 -- (首先在 'www.isbn. ... /cadastro' 中进行搜索,因为验证码)
我尝试了一些代码,现在我只是想获取网站的 html 而不会出现错误 500。
import sys
import urllib
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
BRbase = 'http://www.isbn.bn.br/website/consulta/cadastro/isbn/'
Lista_ISBN = ['9788542209402',
'9788542206937',
'9788521208037']
for isbn in Lista_ISBN:
page = BRbase + isbn
url = Request(page, headers={'User-Agent': 'Mozilla/5.0'})
html = urlopen(url).read()
#code to beautiful soup
try:
#code to beautiful soup and generate bibtex
print(page)
print(html)
except:
print('ISBN {} não encontrado'.format(isbn))
sys.exit(1)
【问题讨论】:
标签: beautifulsoup captcha http-error urlopen