Zhang Wenwei's biography in the History of the Five Dynasties indicated that he served at the office of salt and iron monopolies under the chancellorPei Tan; however, as Pei only served briefly as chancellor in 874, prior to Zhang's passing the imperial examinations, this would not have been possible. See Zizhi Tongjian, vol. 252.
Emperor Zhaozong had left Chang'an on three occasions during his reign—fleeing the potential attacks by the warlords Li Maozhen and Wang Xingyu in 895, returning later in the year; fleeing the attach by Li in 896, returning in 898; and taken forcibly by the eunuchs to Li's domain of Fengxiang Circuit (鳳翔, headquartered in modern Baoji, Shaanxi) in 901, returning in 903. See Zizhi Tongjian, vols. 260, 261, 262, 263. Given that Zhang was mentioned to be the chief imperial scholar when one of the imperial scholars, Liu Can, was made chancellor in 904, according to Liu's biography in the Old Book of Tang, it would appear that the reference here was to the return from Fengxiang in 903. See Old Book of Tang, vol. 179.