'''
&name : xiaowen
&time : 2021/8/19
&content : 获取段子
'''
import requests
from lxml import etree
import re
import time
def get_content(url):
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/7.36 (KHTML, like Gecko) Chrome/3.0.3.61 Safari/7.36"}
resbost = requests.get(url = url,headers = headers)
resbost.encoding = 'utf-8'
html_1 = etree.HTML(resbost.text)
z_div = html_1.xpath('/html/body/div[1]/div/div[2]/div')
#print(z_div)
for i in z_div:
s = i.xpath('./a[1]/@href')[0]
#print(s)
url_1='https://www..com'+s
resbost_1 = requests.get(url = url_1,headers = headers)
resbost_1.encoding = 'utf-8'
html_2 = resbost_1.text
s_1 = re.compile(r'<di* class="content">(?P
text_content = s_1.finditer(html_2)
resbost_1.close()
for j in text_content:
time.sleep(1)
print('\n',j.group("content"))
if name == 'main':
print('欢迎使用本程序