-
Notifications
You must be signed in to change notification settings - Fork 0
/
request_util.py
26 lines (23 loc) · 924 Bytes
/
request_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
from bs4 import BeautifulSoup
def batch_query(domains):
url = "https://ip.tool.chinaz.com/ipbatch"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
data = {
"ips": "\r\n".join(domains),
'submore': '查询'
}
with requests.Session() as session:
response = session.post(url, headers=headers, data=data)
ip_addresses = {}
soup = BeautifulSoup(response.text, "html.parser")
for row in soup.select("table.WhoIpWrap.trime.ww100.tc.lh30 tbody#ipList tr"):
cells = row.find_all("td")
if len(cells) < 4:
continue
ip_address = {cells[0].text.strip() : cells[1].text.strip()}
ip_addresses.update(ip_address)
return ip_addresses