【问题标题】:how would I get only the ip's and port from the website我怎样才能从网站上获得 ip 和端口
【发布时间】:2023-01-18 10:29:12
【问题描述】:
我不知道如何获取 ips 和端口
导入请求
url = "https://proxylist.geonode.com/api/proxy-list?limit=500&page=1&sort_by=lastChecked&sort_type=desc"
session = requests.session()
刮刀 = session.get(url)
data1 = scraper.json()["数据"]
数据 1 = 海峡(数据 1)
file = open(r"C:\Users\chris\OneDrive\Desktop\misc\a\hello.txt", "wb")
file.write(data1.encode('utf8'))
【问题讨论】:
标签:
python
web-scraping
python-requests
【解决方案1】:
import requests
url = "https://proxylist.geonode.com/api/proxy-list?limit=500&page=1&sort_by=lastChecked&sort_type=desc"
session = requests.session()
scraper = session.get(url)
data1 = scraper.json()["data"]
data1 = "
".join([f"{e['ip']}, {e['port']}" for e in data1]) # list comprehension to extract desired values from list
with open(r"C:UserschrisOneDriveDesktopmischello.txt", "wb") as f:
f.write(data1.encode("utf8"))
输出:
...
45.70.237.143, 4145
94.23.4.127, 8444
77.46.138.37, 33608
131.161.223.20, 5678
5.9.251.177, 1080
185.200.38.235, 10820
103.70.159.157, 5678
110.172.137.20, 4673
79.127.35.243, 5678
...