模拟浏览器点击辅助论坛,这里使用的是Xpath路径去定位网页文件元素。
然后使用的是edge的浏览器驱动,使用这段代码前还需要下载一个edge 的驱动,与代码文件放在同一目录下,下载链接在这:
Microsoft Edge WebDriver - Microsoft Edge Developer
根据电脑版本下,一般Windows下这个64就行:
模拟点击运行 代码如下:(每一步的原理就不讲了....没爬虫基础可能也看不懂)
ckwx=[]
from selenium.webdriver import Edge
from selenium.webdriver.edge.options import Options as EdgeOptions
driver = webdriver.Edge("msedgedriver")
url = "https://xs.scqylaw.com/"
driver.implicitly_wait(10)
driver.get(url)
sleep(3)
code=driver.find_element(By.XPATH,'//*[@id="lst-ib"]')
code.send_keys('LSTM')
driver.find_element(By.XPATH,'/html/body/div[1]/center/div[3]/form/div[2]/input[1]').click()
#网页转换,将网页转换到所需的地方
win =driver.window_handles
driver.switch_to.window(win[1])
sleep(2)


现在参考文献的格式都提取出来了ps脚本将文件载入堆栈,装在了ckwx这个列表中,打印查看:

写入word文档
用docx这个包就行:(下载命令——pip install python-docx)
import docx
from docx import shared
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
doc=docx.Document() #创建内存中的word文档对象
doc.styles['Normal'].font.name = 'Times New Roman'
doc.styles['Normal'].font.size = shared.Pt(9)
for i in range(len(ckwx)):
doc.add_paragraph(f"[{i+1}] {ckwx[i]}")
doc.save("参考文献汇总.docx") #保存才能看到结果
最后生成一个word,查看一下效果还不错:

来源:【九爱网址导航www.fuzhukm.com】
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!