'''
翻页获取股吧数据
http://guba.eastmoney.com/
获取10页信息,然后放到指定文件夹中
'''
'''
爬取板块:国产芯片
思路:
找规律
第一页:http://so.eastmoney.com/web/s?keyword=国产芯片
第二页:http://so.eastmoney.com/web/s?keyword=国产芯片&pageindex=2
第三页:http://so.eastmoney.com/web/s?keyword=国产芯片&pageindex=3
'''
import requests,os
def guba(pageindex):
base_url = 'http://so.eastmoney.com/web/s?'
# base_url = 'http://so.eastmoney.com/web/s?keyword=国产芯片&pageindex=4'
params = {
'keyword': '国产芯片',
}
path = './guba/'+pageindex+'/'
if not os.path.exists(path):
os.makedirs(path)
for page in range(1,11):
print(f'——————————————开始下载第{page}页——————————————')
params['pageindex'] = str(page)
file_path = path + str(page) +'.html'
print(requests.get(base_url,params=params).url)
with open(file_path,'w',encoding='utf-8')as f :
f.write(requests.get(base_url,params=params).text)
print('下载完成')
if __name__ == '__main__':
pageindex = input('请输入文件夹名称')
guba(pageindex)