python爬取昵称并保存为vss

ε祈祈猫儿з 提交于 2019-12-06 20:41:28

代码:

 1 import sys
 2 import io
 3 import re
 4 sys.stdout=io.TextIOWrapper(sys.stdout.buffer,encoding='gb18030')
 5 import requests
 6 from bs4 import BeautifulSoup
 7 
 8 def html_save(s):
 9     with open('Name.csv','a')as f:
10         f.write(s+'\n')
11 # soup = BeautifulSoup(html,'index')
12 def getName_link():
13     lst=[]
14     soup = BeautifulSoup(open('Girl.html'))
15     for div in soup.find_all('div',{'class':'babynology_textevidence babynology_bg_grey babynology_shadow babynology_radius left overflow_scroll'}):
16         for strong in div.find_all('strong'):
17             print(strong.find_all('a')[0].text.replace('    ','').replace(' ','').replace('\n',''))
18             # print(strong.find_all('a')[0].get('href').replace('\n',''))
19             i=strong.find_all('a')[0].text.replace('    ','').replace(' ','').replace('\n','')
20             # j=strong.find_all('a')[0].get('href').replace('\n','')
21             # lst.append(j)
22             html_save(i)
23             # html_save(j)
24     # print(lst)        
25     # return lst
26 getName_link()

运行结果:

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!