小编Bri*_*ian的帖子

无法使用剥离或替换删除前导\ n

我试图从以下文本中获取IP:Port:

{
  "supportsHttps": true,
  "protocol": "http",
  "ip": "149.28.159.132",
  "port": "8080",
  "get": true,
  "post": true,
  "cookies": true,
  "referer": true,
  "user-agent": true,
  "anonymityLevel": 1,
  "websites": {
    "example": true,
    "google": true,
    "amazon": false,
    "yelp": false,
    "google_maps": false
  },
  "country": "US",
  "unixTimestampMs": 1558097368515,
  "tsChecked": 1558097368,
  "unixTimestamp": 1558097368,
  "curl": "http://149.28.159.132:8080",
  "ipPort": "149.28.159.132:8080",
  "type": "http",
  "speed": 89.52,
  "otherProtocols": {},
  "verifiedSecondsAgo": 1249
}
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码:

def gimmeproxy():
    r=requests.get("https://gimmeproxy.com/api/getProxy?api_key=45785302-3264-4694-99e1-7c6628c90e6c&get=true&country=US&protocol=http&supportsHttps=true&user-agent=true&websites=google&anonymityLevel=1")
    contents=str(r.content)
    content=contents.split(',')
    IP=content[20]
    print(IP)

    #IP=IP.replace(':','')
    IP = IP.replace('"', '')
    IP = IP.replace(',', '')
    IP = IP.replace("\n", "")
    IP = IP.replace('ipPort', …
Run Code Online (Sandbox Code Playgroud)

python replace strip

3
推荐指数
1
解决办法
41
查看次数

标签 统计

python ×1

replace ×1

strip ×1