亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我正在嘗試獲取代理和端口 我獲取了代理但無法獲取端口 請幫助我

我正在嘗試獲取代理和端口 我獲取了代理但無法獲取端口 請幫助我

慕桂英546537 2023-07-18 17:44:50
import requestsfrom bs4 import BeautifulSoup as bsheaders = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"}url = "https://www.proxyscan.io/"r=requests.get(url,headers=headers)soup = bs(r.content,"html.parser")a = soup.findAll(scope="row")a = str(a).replace("<th scope=\"row\">", "").replace("</th>", "").replace("[","").replace("]","").replace(" ","")a = a.split(",")for proxy in a:    print(proxy)
查看完整描述

2 回答

?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

import requests

from bs4 import BeautifulSoup as bs

    

headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"}


url = "https://www.proxyscan.io/"

    

r=requests.get(url,headers=headers)

    

soup = bs(r.content,"html.parser")


a = soup.findAll(scope="row")


a = str(a).replace("<th scope=\"row\">", "").replace("</th>", "").replace("[","").replace("]","").replace(" ","")


a = a.split(",")

    

    

for proxy in a: 

   print(proxy)


查看完整回答
反對 回復 2023-07-18
?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

您可以使用find_next_siblings()函數來獲取下一個可用標簽。


因此,通過敏銳地觀察解析后的html,我們可以看到端口是代理之后的下一個標簽。因此我們可以循環變量a并找到下一個相鄰的標簽。


從 所返回的數組中獲取第一個元素find_next_siblings()。


大概是這樣的<td>4145</td>。從中清理 html 標簽或從中提取字符串td,您應該獲得端口號。


for i in a:

    full = i.find_next_siblings()[0]

    port = str(full).replace("<td>","")

    port = str(port).replace("</td>", "")

    print(port)


查看完整回答
反對 回復 2023-07-18
  • 2 回答
  • 0 關注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號