headers = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", } html = requests.get(url=url, headers=headers).text
f = open('./课程/08course/08.html', 'w', encoding='utf-8') f.write(html) f.close()
root = etree.HTML(html) trs = root.xpath('//tr')
f = open('./课程/08course/data08.txt', 'w', encoding='utf-8') for tr in trs: tds = tr.xpath('./td') s = '' for td in tds: s = s + str(td.xpath('string(.)')) + '|' print(s) if s!= '': f.write(s + '\n')
headers = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", } # 传入 post 请求中的数据 payload = {'level': '8'} # post 请求 html = requests.post(url=url, headers=headers, data=payload).text
f = open('./课程/08course/08.html', 'w', encoding='utf-8') f.write(html) f.close()
root = etree.HTML(html) trs = root.xpath('//tr')
f = open('./课程/08course/data08.txt', 'w', encoding='utf-8') for tr in trs: tds = tr.xpath('./td') s = '' for td in tds: s = s + str(td.xpath('string(.)')) + '|' print(s) if s!= '': f.write(s + '\n')