python - 使用 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-Referer,但没有成功。我只得到header response 200 & header-content,但没有来自源代码的一个字母,只是一个没有任何描述的错误。没有错误且有内容地打开此第 3 页的唯一方法是单击第 2 页上的链接。这是一个完全公开的网站,没有理由建立referer 或任何其他加密。那么问题是什么以及如何解决呢?
解决方案
只要您包含正确的推荐人,您的标题应该可以正常工作。您接收 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
推荐阅读
- nestjs - 如何在nestjs中向客户端广播?
- version - MINIO:对象的GetVersions
- openlayers - Openlayers,更新样式后功能消失
- react-native - store.dispatch 没有更新 redux 中的状态?
- android - 将视图绑定与 Fragments Android 结合使用
- javascript - 我可以用 Javascript 添加日历事件吗?
- vue.js - 如何通过 gapi 实现注销
- docker - 每当我尝试在我的 vs 代码中打开 docker 时,都会发生错误
- android - Flutter 发送消息/数据到本地 IP
- swift - swiftui视图:潜在索引超出范围的if语句