What happens?
You try to find_all()
the header info with multiple class names, what wont work this way:
find_all("div",{"class":"z-padtop2 xgray"})
How to fix that?
Use the css selector, think it is much easier to chain the classes this way:
soup.select('div.z-padtop2.xgray')
How to get the number of follows?
If you do not wanna use regex
just split()
the text and select the value by .index('Follows:')+1
follows = items.get_text().split()
list_header.append(follows[follows.index('Follows:')+1])
Example
from selenium import webdriver
from bs4 import BeautifulSoup as soup
from time import sleep
driver = webdriver.Chrome(executable_path='C:Program FilesChromeDriverchromedriver.exe')
url = "https://www.fictionpress.com/u/541077/Imperfect-Princess"
driver.get(url)
sleep(5)
soup = BeautifulSoup(driver.page_source, "lxml")
list_header = []
header = soup.select('div.z-padtop2.xgray')
for items in header:
try:
follows = items.get_text().split()
list_header.append(follows[follows.index('Follows:')+1])
except:
list_header.append('no follows')
continue
driver.quit()
list_header
Output
['1,174',
'364',
'1,965',
'34',
'61',
'215',
'18',
'859',
'320',
'1,483',
'224',
'196',
'68',
'57',
'12',
'208',
'31',
'33',
'25',
'7',
'no follows',
'20',
'26',
'6',
'31']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…