from selenium import webdriver
import time
import re
driver_path = r"C:\Users\Administrator\Desktop\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(executable_path=driver_path)
driver.get('https://www.ptpress.com.cn')
time.sleep(5)
driver.execute_script('window.scrollTo(0,document.body.scrollHeight)')
html=driver.page_source
name=re.findall('<span class="name">(.*?)</span>', html, re.DOTALL)
time=re.findall('<span class="date">(.*?)</span>', html, re.DOTALL)
data_1=name
data_2=time
##存储
import pymongo
client=pymongo.MongoClient("mongodb://localhost:27017/")
db=client.pythondb
MONGO_URL='localhost'
client=pymongo.MongoClient(MONGO_URL)
db=client['pythondb']
collection=db.test
for i,j in zip(data_1,data_2):
data_time=j
mainTitle=i
a={'created':data_time,
'mainTitle':mainTitle
}
collection.insert_one(a)
print(a)
问题四(正则表达式)
最新推荐文章于 2024-08-10 10:46:00 发布