This is a part of my code. Sorrry I can not show you the url, but I have tested the url and it can correctly lead to the web I expect.
response = requests.get(base_url)
if response.status_code == 200:
soup = BeautifulSoup(response.content, 'html.parser')
c = response.content.decode('utf-8')
print(c)
After I get the response content, the header part of the content as follows:
The page is used for installing the Service Worker.
When a user visits for the first time, no matter which resource is requested (including the homepage), this page is returned.
I want to know how to successfully get the response content. Thanks for you answer!
I try to add a http header to requests.get(base_url, headers=header), but still get the same page, as follows:
<!--
This page is used to install Service Worker.
Whenever a user visits for the first time, no matter which resource is requested (including the homepage), this page will be returned.
This page is designed to be as simple as possible and compatible with all browsers.
-->
<html>
<head>
<meta charset="utf-8">
</head>
<body id="t">
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" fill="none"><circle cx="50"
cy="50" r="25.944" stroke="#93dbe9"><animate attributeName="r" calcMode="spline" values="0;40" keyTimes="0;1" dur="1" keySplines="0 0.2 0.8 1" begin
="-0.5s" repeatCount="indefinite" stroke-width="2"/><animate attributeName="opacity" calcMode="spline" values="1;0" keyTimes="0;1" dur="1" keySplines
="0.2 0 0.8 1" begin="-0.5s" repeatCount="indefinite" stroke-width="2"/></circle><circle cx="50" cy="50" r="40" stroke="#689cc5"><animate attributeNa
me="r" calcMode="spline" values="0;40" keyTimes="0;1" dur="1" keySplines="0 0.2 0.8 1" begin="0s" repeatCount="indefinite" stroke-width="2"/><animate
attributeName="opacity" calcMode="spline" values="1;0" keyTimes="0;1" dur="1" keySplines="0.2 0 0.8 1" begin="0s" repeatCount="indefinite" stroke-width="2"/></circle></svg>
<script>
// window.location.href="https://www.baidu.com";
function reload() {
// Set the minimum refresh interval to prevent continuous refreshing when errors occur
var curr = Date.now()
try {
var last = +sessionStorage._ts || 0
sessionStorage._ts = curr
if (curr - last < 100) {
return setTimeout(reload, 5000)
}
} catch (err) {
}
location.reload()
}
function onfail(err) {
showErr(err.message)
}
function showErr(str) {
t.innerHTML = str
}
function getRootPath() {
// https://a.com/ -> /
// https://a.com/index.html -> /
// https://a.com/path/to/ -> /path/to/
// https://a.com/path/to -> /path/to/
// https://a.com/path/to/index.html -> /path/to/
return location.pathname
.replace(//-+https?:.+/, '')
.replace(/\w+.\w+$/, '')
.replace(//*$/, '/')
}
function main() {
//alert(document.referrer)
if (!self.isSecureContext) {
showErr('This program requires an HTTPS site')
return
}
if (!self.ReadableStream) {
showErr('Please use the latest HTML5 browser')
return
}
var sw = navigator.serviceWorker
if (!sw) {
var ua = navigator.userAgent
if (/Firefox/.test(ua)) {
showErr('This website does not support FireFox private mode')
}
else if (/iPhone|iPad/.test(ua)) {
showErr('Please use Safari browser on iOS')
}
return
}
sw
.register(getRootPath() + 'sw.js')
.then(reload)
.catch(onfail)
}
main()
</script>
</body>
</html>