[Python] 纯文本查看 复制代码 import requests
from lxml import etree
import time
import re
url = 'https://www.app178.com/dujia/248082.html'
resp = requests.get(url)
resp.encoding = 'utf-8'
html = etree.HTML(resp.text.encode('gbk').decode('gbk'))
today = time.localtime()[2]
for i in range(2, 5):
answers = html.xpath(f'//*/table/tbody/tr[{i}]//td/text()')
day = re.findall('.*?月(.*?)日', answers[0])[0]
if int(day) == today:
answer = ': '.join(answers)
print(answer)
运行效果:
[Asm] 纯文本查看 复制代码 8月20日: 天气炎热,待在室内就不会得热射病了吗: 并不是
8月20日: 经常滴眼药水能治疗干眼症吗: 不能 |