python bs64爬取中國工程院院士資訊

2021-10-08 23:28:59 字數 1841 閱讀 6458

作為乙個渣碩已經畢業一年了,也工作一年了,得了空閒來寫寫文章。

前段時間,有個老師叫我寫個爬取中國工程院院士資訊的爬蟲,我寫了個大概的**來實現。

先說一下做這個的整體思路吧:

開門見山的說:就是領導想要看看申請院士,從業者的經歷等等資訊,為了滿足領導的需求,我就開始實現我的爬蟲程式了

cotent_url=main_http+i['href'] #拼接url 獲取每個url下院士的資訊

cotent_detail = requests.get(url=cotent_url)

main_cotent_detail=beautifulsoup(cotent_detail.text,'html.parser').find_all(name='div',class_='intro')

print(main_cotent_detail[0].find_all('p'))

string_content= main_cotent_detail[0].find_all('p')

for i in string_content:

# print(type(i)

string=str(i).replace('','')

string=string.replace('','')

string = string.replace('

', '')

string =string.replace('

, ','')

string = string + '\n'

file.write(string.encode('utf-8'))

stringb = ['a','b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',

'j', 'k', 'l', 'm', 'n', 'o','p', 'q', 'r', 's',

't', 'u', 'v', 'w', 'x', 'y', 'z']

main_url='/cae/html/main/col48/column_48_'

tail_url='.html'

fullpath = 'c:\\users\\administrator\\desktop\\professor.txt' #爬取資訊存放的路徑

with open(fullpath, 'wb+')as file:

for i in stringb:

url = main_url+i+tail_url

# print( url)

get_content(url,file)

file.close()

看完了吧。其實還是有假設和提公升部分,應急所以就寫了這麼多

爬取中國天氣

import requests from bs4 import beautifulsoup def parser page url headers response requests.get url,headers headers text response.content.decode utf 8...

中國災害預警爬取解析

有獲取災害資訊提醒的需求,但是發現並沒有開發的api 已有的api都需要付錢。天氣預報api,可以看知乎的這邊文章。網上的天氣 api 哪乙個更加可靠?裡面的普通的天氣預報部分免費,但是災害預警的api都是需要收費的。於是自己去摸索了。最後通過發f12發現了中國天氣網中可用的請求 順便寫了下解析使用...

豆瓣影評爬取 中國機長

10月大火的中國機長相信大家都看過了吧 悄悄的說,我還有二刷?超級超級超級超級喜歡袁泉姐姐,溫柔又堅定,真誠又勇敢!import requests from bs4 import beautifulsoup import time import pandas as pd import os def ...