使用Python获取公共网站的内容

2024-05-13 08:47:49 发布

您现在位置: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'}

点击链接可找到最后一个子ULR和详细信息。我真的想尽一切办法从3号卫星上获取数据。站点,带有POST、GET、VBA、PYTHON引用程序,但未成功。我刚刚得到标题响应200&标题内容,但源代码中没有一个字母,只是一个没有任何说明的错误。要打开第3页而不出错且包含内容,唯一的方法是单击第2页上的链接。这是一个完全公开的网站,没有理由建立在引用或任何其他加密。那么问题是什么?如何解决


Tags: namesend标题内容by链接shorder
1条回答
网友
1楼 · 发布于 2024-05-13 08:47:49

你的标题应该很好,只要你包括正确的推荐人。也许你接收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

相关问题 更多 >