You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import copy
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome("./venv/chromedriver.exe")#本地浏览器驱动地址,自行跟换
driver.implicitly_wait(60)
def get_book():
# http://www.ibiqu.org/modules/article/search.php?searchkey=
# #搜索书籍
Preurl = "http://www.ibiqu.org/modules/article/search.php?searchkey="
book_name = input("请输入书名:")
url = Preurl + book_name
driver.get(url)
#定位所有标签
bookinfor = driver.find_elements(by=By.CSS_SELECTOR, value=".grid .odd")
#存储书籍信息nameurlwriterlasttime
books = []
book = {}
for i in range(len(bookinfor)):
if (i + 1) % 3 == 1:
book["name"] = bookinfor[i].text
book["url"] = bookinfor[i].find_element(By.TAG_NAME,"a").get_attribute("href")
if (i + 1) % 3 == 2:
book["writer"] = bookinfor[i].text
if (i + 1) % 3 == 0:
book["lasttime"] = bookinfor[i].text
booki = copy.deepcopy(book)
books.append(booki)
print(books)
if __name__ == "__main__":
get_book()
while True:
pass