为什么我的运行只显示数据的最后一个,还有就是我的程序一运行就出现很多个文件,该怎么解决啊?
import requests
import xlwings as xw
import json
from lxml import etree
if name == 'main':
url = 'https://etaps.org/2017/tacas'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
}
meet_text = requests.get(url=url, headers=headers).text
tree = etree.HTML(meet_text)
div_list = tree.xpath("//div[@class='module-inner2']")
for div in div_list:
huiyi_list = div.xpath('./p/a')
for huiyi in huiyi_list:
huiyi_name = '23rd International Conference on Tools and Algorithms for the Construction and Analysis of Systems '
theme = 'POST 2017'
time = '22-29 April 2017'
huiyi_S = ''
huiyi_Z = huiyi.xpath("//div[@class='module-inner2']/p[1]/a/text()")
huiyi_P = huiyi.xpath("//div[@class='module-inner2']/p[position()>2]/a/text()")
# for i in huiyi_P:
# print(i)
# print(i)
huiyi_school = huiyi.xpath("//div[@class='module-inner2']/p/text()")
for teama, teamb in zip(huiyi_P, huiyi_school):
# for o in huiyi_school:
# pass
# print(o)
# url_list = url
# print(i,o)
# print(huiyi_Z)
# print(huiyi_school)
# header = ['会议名称','会议主题','会议时间','主题演讲人','会议主席','参会人员','人员列表','机构']
# data = [huiyi_name,theme,time,huiyi_S,huiyi_Z,huiyi_P,huiyi_school,url_list]
wb = xw.Book()
sht = wb.sheets('sheet1')
sht.range("A1").value = "会议名称"
sht.range("B1").value = "会议主题"
sht.range("C1").value = "会议时间"
sht.range("D1").value = "主题演讲人"
sht.range("E1").value = "会议主席"
sht.range("F1").value = "参会人"
sht.range("G1").value = "机构"
sht.range("H1").value = "list_url"
for i in range(8):
huiyi_name = json.dumps('6th International Conference on Principles of Security and Trust')
sht.range(f'A{i + 2}').value = huiyi_name
theme = json.dumps('POST 2017')
sht.range(f'B{i + 2}').value = theme
time = json.dumps("22-29 April 2017")
sht.range(f'C{i + 2}').value = time
huiyi_S = ''
sht.range(f'D{i + 2}').value = huiyi_S
huiyi_Z = ''
sht.range(f'E{i + 2}').value = huiyi_Z
huiyi_P = json.dumps(teama)
sht.range(f'F{i + 2}').value = teama
huiyi_school = json.dumps(teamb)
sht.range(f'G{i + 2}').value = teamb
url = json.dumps('https://etaps.org/2017/post')
sht.range(f'H{i + 2}').value = url
print("会议名称:" + huiyi_name, "会议主题:" + theme, "会议时间:" + time, "主题演讲人:" + huiyi_S, "会议主席:" + huiyi_Z,
"参会人:" + huiyi_P, "机构:" + huiyi_S, "list_url:" + url)