首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >访问有请求的网站时的不同内容

访问有请求的网站时的不同内容
EN

Stack Overflow用户
提问于 2021-08-11 14:39:19
回答 1查看 33关注 0票数 1

我正在尝试使用公司的名称在ARIN中自动获得相应的句柄ids,比如"Google“。

https://search.arin.net/rdap/?query=google*

我的天真方法是使用requestsBeautifulSoup

代码语言:javascript
复制
import requests
from bs4 import BeautifulSoup

html = 'https://search.arin.net/rdap/?query='
comp = 'google*'

r = requests.get(html + comp)
soup = BeautifulSoup(r.text, 'html.parser')

#example search
search = soup.body.find_all(text = "Handle$")

然而,当我使用requests时,我没有得到与我简单地使用Google Chrome时相同的输出。requests返回的html代码不同,我无法访问相应的句柄。

有人知道怎么修改代码吗?

EN

回答 1

Stack Overflow用户

发布于 2021-08-11 14:47:21

您在页面上看到的数据是从外部API URL加载的。您可以使用requests模块进行模拟:

代码语言:javascript
复制
import json
import requests

api_url = "https://rdap.arin.net/registry/entities"
params = {"fn": "google*"}

data = requests.get(api_url, params=params).json()

# pretty print the data:
print(json.dumps(data, indent=4))

打印:

代码语言:javascript
复制
...

        {
            "handle": "GF-231",
            "vcardArray": [
                "vcard",
                [
                    [
                        "version",
                        {},
                        "text",
                        "4.0"
                    ],
                    [
                        "fn",
                        {},
                        "text",
                        "GOOGLE FIBER INC"
                    ],
                    [
                        "adr",
                        {
                            "label": "3425 MALONE DR\nCHAMBLEE\nGA\n30341\nUnited States"
                        },
                        "text",
                        [
                            "",
                            "",
                            "",
                            "",
                            "",
                            "",
                            ""
                        ]
                    ],
                    [
                        "kind",
                        {},
                        "text",
                        "org"
                    ]
                ]
            ],

...
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68744125

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档