在wbpag的框中获取某些内容时遇到问题

2024-04-25 02:32:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图解析位于this website最底部的一个类似于盒子的容器中的内容,但在page source中找不到它们的存在。我已经试着创建一个脚本来联系他们。你知道吗

import requests
from bs4 import BeautifulSoup

url = 'https://www.proxy-list.download/HTTPS'

r = requests.get(url)
soup = BeautifulSoup(r.text,'lxml')
item = soup.select_one("a#btn3").text
print(item)

输出结果:

Copy to clipboard

我想要这个:

104.248.115.236:80
104.248.53.46:3128
104.236.248.219:3128
104.248.115.236:3128
104.248.115.236:8080
104.248.184.16:8080

这就是内容在该页面中的显示方式:

enter image description here


Tags: textimport脚本urlsource内容pagewebsite
1条回答
网友
1楼 · 发布于 2024-04-25 02:32:03

请尝试此链接https://www.proxy-list.download/api/v0/get?l=en&t=https(您可以使用开发工具找到此链接),以获得所有这些链接,如下面所示:

import requests
from bs4 import BeautifulSoup

url = 'https://www.proxy-list.download/api/v0/get?l=en&t=https'

r = requests.get(url)
for item in r.json()[0]['LISTA']:
    proxy = f"{item['IP']}{':'}{item['PORT']}"
    print(proxy)

相关问题 更多 >