|
发表于 2022-3-23 02:15:11
|
显示全部楼层
本楼为最佳答案
 - #!/usr/bin/env python3
- # _*_ coding: utf-8 _*_
- # Developer: suchocolate
- # Date: 2022-03-23 01:16
- # File name: pc1.py
- # Development tool: PyCharm
- import requests
- from lxml import etree
- def get_args(txt, f=0):
- html = etree.HTML(txt)
- sta = html.xpath('//input[@id="__VIEWSTATE"]/@value')[0]
- gen = html.xpath('//input[@id="__VIEWSTATEGENERATOR"]/@value')[0]
- eve = html.xpath('//input[@id="__EVENTVALIDATION"]/@value')[0]
- if not f:
- return sta, gen, eve
- else:
- zones = html.xpath('//select[@name="ctl00$MainContent$ddl_RD_CODE"]/option/@value')
- return sta, gen, eve, zones
- def main():
- headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
- 'Origin': 'http://spf.szfcweb.com',
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
- 'Host': 'spf.szfcweb.com',
- 'Accept-Encoding': 'gzip, deflate',
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Upgrade-Insecure-Requests': '1',
- 'Referer': 'http://spf.szfcweb.com/szfcweb/(S(r2ga2fthdmz1mel1rym2xyat))/DataSerach/MITShowList.aspx'}
- url = 'http://spf.szfcweb.com/szfcweb/(S(r2ga2fthdmz1mel1rym2xyat))/DataSerach/MITShowList.aspx'
- r = requests.get(url, headers=headers)
- sta, gen, eve, zones = get_args(r.text, f=1)
- for zone in zones:
- data = {'__EVENTTARGET': '',
- '__EVENTARGUMENT': '',
- '__LASTFOCUS': '',
- '__VIEWSTATE': sta,
- '__VIEWSTATEGENERATOR': gen,
- '__EVENTVALIDATION': eve,
- 'ctl00$MainContent$txt_Com': '',
- 'ctl00$MainContent$txt_Pro': '',
- 'ctl00$MainContent$ddl_RD_CODE': zone,
- 'ctl00$MainContent$txt_ysz': '',
- 'ctl00$MainContent$bt_select': '查询',
- 'ctl00$MainContent$PageGridView1$ctl12$PageList': '0'
- }
- r = requests.post(url, headers=headers, data=data)
- # print(r.status_code)
- print(r.text)
- sta, gen, eve = get_args(r.text)
- if __name__ == '__main__':
- main()
复制代码 |
|