import requests
from bs4 import BeautifulSoup
import csv
url = "https://csie.asia.edu.tw/faculty/professors"
r = requests.get(url)
r.encoding = "utf8"
soup = BeautifulSoup(r.text, "lxml")
tag_table = soup.find(attrs={"class":"row contact-category"})
ALL_Professors = tag_table.find_all("div",class_="col-sm-12")
csvfile = "AU_CSIE_Professor_jdwang2020_5_20_BIG5_FieldName.csv"
with open(csvfile, 'w+', newline='', encoding="big5") as fp:
writer = csv.writer(fp)
Fieldnames = ["姓名","學歷","辦公室","分機","E-mail"]
writer.writerow(Fieldnames)
for One in ALL_Professors:
OneRecordList = []
print (One.find('h2','card-header').string)
OneRecordList.append(One.find('h2','card-header').string)
ALL_card_description = One.find_all("p",class_="card-description")
for oneItem in ALL_card_description:
OneRecordList.append(oneItem.text.split(':')[1].replace("\t","").replace(" ",""))
print(OneRecordList)
writer.writerow(OneRecordList)
請問爬蟲這個紅色箭頭指分機的要怎把它改成可以填到信箱那一格,用list會沒辦法移過去,想請問怎用字典移過去,求大神。
p.s不好意思第一次發文,已發出程式碼。