使用 Python 获取 public 网站的内容

Get the content of a public website with Python

我面临着一个真正的谜团:

VBA

 .send "land_abk=sh&ger_name=Norderstedt&order_by=2&ger_id=X1526"

Python

headers = {'User-Agent': 'python-requests/2.24.0', 'Accept-Encoding':'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive','Referer': 'https://url'}

单击 link 会转到最后一个子 ULR 和详细信息。我尝试了从 3. 站点获取数据的所有方法,使用 POST、GET、VBA、PYTHON-Referer,但没有成功。我只得到 header response 200 & header-content,但没有来自源代码的单个字母,只是一个没有任何描述的错误。要正确打开第 3 页且包含内容的唯一方法是单击第 2 页上的 link。这是一个完全 public 的网站,没有理由建立引用或任何其他加密。那么问题是什么以及如何解决?

您的 headers 应该可以正常工作,只要您包含正确的推荐人。也许您接收 html 的方式有问题。这对我有用:

使用 urllib3

import urllib3
from bs4 import BeautifulSoup

URL = "https://www.zvg-portal.de/index.php?button=showZvg&zvg_id=755&land_abk=sh"
headers = {
    "Referer": "https://www.zvg-portal.de/index.php?button=Suchen",
}

http = urllib3.PoolManager()
response = http.request("GET", URL, headers=headers)
html = response.data.decode("ISO-8859-1")

soup = BeautifulSoup(html, "lxml")
print(soup.select_one("tr td b").text)
# >> 0061 K 0012/ 2019

使用请求

import requests

URL = "https://www.zvg-portal.de/index.php?button=showZvg&zvg_id=755&land_abk=sh"

headers = {
    "Referer": "https://www.zvg-portal.de/index.php?button=Suchen",
}
html = requests.get(URL, headers=headers).text

print("Versteigerung im Wege der Zwangsvollstreckung" in html)
# >> True

使用Python 2:

import urllib2

URL = "https://www.zvg-portal.de/index.php?button=showZvg&zvg_id=755&land_abk=sh"

req = urllib2.Request(URL)
req.add_header("Referer", "https://www.zvg-portal.de/index.php?button=Suchen")
html = urllib2.urlopen(req).read()

print("Versteigerung im Wege der Zwangsvollstreckung" in html)
# >> True