爬取星座

#!/usr/bin/env python 
# -*- coding:utf-8 -*-

import requests
from bs4 import BeautifulSoup
import csv
import os
import re
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36'
}
link = "https://www.xzw.com/fortune/"
fetch_regex = re.compile(r"^.*?(.*?)(.*?).*?width:(\d*)%.*?

(.*?)\[ div.alb dl") result_list = [] for dl in dls: result = fetch_regex.match(str(dl)) if result: result_list.append([result.group(1),result.group(2),str(int(result.group(3))//20) + "颗星",result.group(4)]) #print(result_list) with open(save_path,"w",newline="") as f: print("正在将内容存储到csv文件中...") writer = csv.writer(f) writer.writerows(result_list) print("完成!") if __name__ == "__main__": fetch_msg(link)

你可能感兴趣的:(爬取星座)