Skip to content

Commit cac9c93

Browse files
committed
delete my pwd
1 parent 80d8404 commit cac9c93

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

baidu_tieba/scrapy.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
# 微信公众号 月小水长(ID: inspurer)
99

1010
import requests, math,os.path
11+
from set import USER_NAME,PASSWORD
1112
from bs4 import BeautifulSoup
1213
BASE_PATH = 'imgs'
1314
if not os.path.exists(BASE_PATH):
1415
os.mkdir(BASE_PATH)
1516
def main():
1617
session = login()
17-
keyword = input('请输入贴吧名称:')
18+
keyword = input('请输入你想要爬取图片的贴吧:')
1819
# 构建贴吧主页url
1920
index_url = "https://tieba.baidu.com/f?kw={}".format(keyword)
2021
# 获取帖子总页数(经过测试发现不登录的情况下是无法获取帖子数目的)
@@ -38,19 +39,15 @@ def main():
3839
for img in img_urls:
3940
i = i + 1
4041
with open(img_dir + "/" + str(i) + '.jpg', 'wb') as f:
41-
print("正在下载第" + str(i) + "张图片" )
42+
print("开始下载第" + str(i) + "张图片" )
4243
f.write(session.get(img.attrs['src']).content)
43-
print("图片下载完毕!")
44+
print("图片下载成功!")
4445
# 模拟登陆的方法
4546
def login():
46-
# 登录的用户名
47-
username = '18272415912'
48-
# 登录的密码
49-
password = 'CSUxiaotao1998'
5047
# 登录所需的参数
5148
login_data = {
52-
'username': username,
53-
'password': password,
49+
'username': USER_NAME,
50+
'password': PASSWORD,
5451
'u': 'https://tieba.baidu.com/index.html?traceid=#',
5552
#tb 贴吧,表明是从百度贴吧登录百度站点的
5653
'tpl': 'tb',
@@ -114,4 +111,4 @@ def get_tiezi_list(tiezi_url, session):
114111
return static_tiezi_urls
115112

116113
if __name__ == '__main__':
117-
main()
114+
main()

baidu_tieba/set.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# -*- coding: utf-8 -*-
2+
# author: inspurer(月小水长)
3+
# pc_type lenovo
4+
# create_time: 2019/5/27 10:47
5+
# file_name: set.py
6+
# github https://github.com/inspurer
7+
8+
# 微信公众号 月小水长(ID: inspurer)
9+
10+
# 登录的用户名,一般是手机号
11+
USER_NAME = '**********'
12+
13+
# 登录密码
14+
PASSWORD = '**********'

baidu_translation/baidu.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,13 @@ def getSign(self, gtk, word):
4545
return sign
4646

4747
if __name__ == "__main__":
48-
result = baidu().translate("华为")
49-
print(result)
48+
t = baidu()
49+
to_translate = input('请输入待翻译词:')
50+
while True:
51+
result = t.translate(to_translate)
52+
print('{}的翻译结果是:{}'.format(to_translate,result))
53+
to_translate = input('请继续输入待翻译词,或者回车结束')
54+
# 翻译结束
55+
if len(to_translate) == 0:
56+
print('本次翻译结束')
57+
break

0 commit comments

Comments
 (0)