Skip to content

Commit 0febdf2

Browse files
committed
selenium
1 parent 3fd2ddd commit 0febdf2

26 files changed

Lines changed: 7202 additions & 23 deletions

PythonDemo/.spyproject/workspace.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ save_non_project_files = False
66

77
[main]
88
version = 0.1.0
9-
recent_files = ['E:\\GitHubWorkplace\\Python\\PythonDemo\\Matplotlib\\demo19.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\Matplotlib\\demo18.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinQianming.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixin.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotGroup.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinchatRobotSingle.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinItchatSexAs.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\a_new_hope.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\colored.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\wordcloud\\examples\\masked.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\spider\\weixinlocation.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\SnowNLP\\test.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\SnowNLP\\demo1.py']
9+
recent_files = ['C:\\Users\\Administrator\\.spyder-py3\\temp.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arrayboolean.py', 'E:\\GitHubWorkplace\\Python\\PythonDemo\\numpy\\arraymethod.py']
1010

PythonDemo/readme.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
wordcloud词云 jieba分词 itchat wxpy微信相关
1+
wordcloud词云 jieba分词 itchat wxpy微信相关
2+
Matplotlib第三库
3+
numpy第三库

PythonDemo/spider/qqbotRobot.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

PythonSpider/.spyproject/workspace.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ save_non_project_files = False
66

77
[main]
88
version = 0.1.0
9-
recent_files = ['C:\\Users\\Administrator\\.spyder-py3\\temp.py']
9+
recent_files = ['C:\\Users\\Administrator\\.spyder-py3\\temp.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\SimpleCrawler.py', 'E:\\GitHubWorkplace\\Python\\PythonSpider\\followers.json']
1010

PythonSpider/SimpleCrawler.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import requests
3+
class SimpleCrawler:
4+
init_url = "https://zhuanlan.zhihu.com/api/columns/pythoneer/followers"
5+
offset = 0
6+
def crawl(self, params = None): #必须指定UA, 否则知乎服务器会判定请求不合法
7+
headers = {
8+
"Host": "zhuanlan.zhihu.com",
9+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
10+
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36",
11+
}
12+
response = requests.get(self.init_url, headers = headers, params = params)
13+
print(response.url)
14+
data = response.json()# 7000 表示所有关注量# 分页加载更多, 递归调用
15+
while self.offset < 7000:
16+
self.parse(data)
17+
self.offset += 20
18+
params = {
19+
"limit": 20,
20+
"offset": self.offset
21+
}
22+
self.crawl(params)
23+
def parse(self, data):
24+
#以json格式存储到文件
25+
with open("followers.json", "a", encoding = "utf-8") as f:
26+
for item in data:
27+
f.write(json.dumps(item))
28+
f.write('\n')
29+
if __name__ == '__main__':
30+
SimpleCrawler().crawl();

PythonSpider/cookie.txt

Whitespace-only changes.

PythonSpider/followers.json

Lines changed: 7000 additions & 0 deletions
Large diffs are not rendered by default.

PythonSpider/selenium/csdn.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Sat Mar 17 18:30:06 2018
4+
5+
@author: Administrator
6+
"""
7+
8+
from selenium import webdriver
9+
## 创建浏览器对象
10+
browser = webdriver.Firefox()
11+
## 打开小米社区网站
12+
browser.get('https://passport.csdn.net/account/login')
13+
browser.find_element_by_xpath("//*[@id='username']").clear()#清空输入框
14+
browser.find_element_by_xpath("//*[@id='username']").send_keys("1361583339@qq.com")#输入账号
15+
browser.find_element_by_xpath("//*[@id='password']").clear()#清空输入框
16+
browser.find_element_by_xpath("//*[@id='password']").send_keys("ks1996721kr")#输入密码
17+
browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]/div/div[1]/div/form/input[8]").click()#登录

0 commit comments

Comments
 (0)