forked from jorhelp/Ingram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
targetMaker.py
30 lines (26 loc) · 927 Bytes
/
targetMaker.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
27
28
29
30
# _*_ codign:utf8 _*_
"""====================================
@Author:Sadam·Sadik
@Email:[email protected]
@Date:2022/12/23
@Software: PyCharm
@disc:
======================================="""
import requests
from lxml import etree
def generate(code: int):
resp = requests.get(f"http://ip.bczs.net/city/{code}", headers={
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
})
html = etree.HTML(resp.text)
trs = html.xpath("//tbody/tr")
with open(f"targets-{code}.txt", "w", encoding="utf-8") as f:
for i, tr in enumerate(trs):
tds = tr.xpath(".//td")
start = tds[0].xpath(".//a")[0].text
end = tds[1].text
target = f"{start}-{end}"
f.write(target + "\n")
print(f"{i}. {target}")
if __name__ == '__main__':
generate(650100)