【发布时间】:2020-02-25 09:47:06
【问题描述】:
我要爬取页面 url = 'https://e-justice.europa.eu/searchBris.do' 来提交我自己的信息。我使用 requests.get(url) 来获取页面的 html 内容。
requests.get(url)
但我得到重定向页面作为请求的输出,如下所示:
\n\n\n\n\n\n\n<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n<html lang="en">\n <head>\n <title>Find a company</title>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n\n <script> \n top.location.reload();\n </script>\n\n <noscript><meta http-equiv="refresh" content="0;url=https://e-justice.europa.eu/searchBris.do"/></noscript>\n </head>\n <body>\n <h1>Redirecting...</h1>\n </body>\n</html>
我也测试了allow_redirect选项以及session.get()和session.post()方案如下,但是重定向的输出依然存在,并且url的html的访问被拒绝了。
requests.get(url, allow_redirects=True)
session.get(url, allow_redirects=True)
requests.post(url, allow_redirects=True)
session.post(url, allow_redirects=True)
有没有办法获取原始url的内容?
【问题讨论】:
标签: python-3.x beautifulsoup request web-crawler