Skip to content

Commit 24a3dfe

Browse files
author
LaoBian
committed
cgi 服务基础
1 parent c44a777 commit 24a3dfe

File tree

8 files changed

+936
-57
lines changed

8 files changed

+936
-57
lines changed

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 70 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ python案例分享
66
案例三:python selenium使用<br>
77
案例四:unittest_selenium使用<br>
88
案例五:python selenium递归<br>
9+
案例六:python cgi项目<br>
10+
911

1012

1113

cgiProject/cgi-bin/index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
html = """
2+
<html>
3+
<head>
4+
<title>
5+
image
6+
</title>
7+
</head>
8+
<body>
9+
<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562231356345&di=14d608194de00e8b04ec741b3b107ab9&imgtype=0&src=http%3A%2F%2Fimage.whhost.net%2Fuploads%2F20180413%2F22%2F1523628708-NofpLxkrHM.jpg">
10+
</body>
11+
</html>
12+
""" #要返回的数据 response 的body
13+
print("content-type:text/html") #返回响应的头部,具体描述的要返回的内容类型,在cgi当中用print进行返回
14+
print("\n") #返回头部结束
15+
print(html) #返回响应的body

cgiProject/image.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<html>
2+
<head>
3+
<title>
4+
image
5+
</title>
6+
</head>
7+
<body>
8+
<img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1562231356365&di=0d1ca146f287f56b35b9c271e0cc08ac&imgtype=0&src=http%3A%2F%2Fwww.zhongaigou.com%2Fuploadfiles%2F33191%2F9133%2520%2528295%2529.jpg">
9+
</body>
10+
11+
</html>

cgiProject/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html>
2+
<head>
3+
<title>
4+
index
5+
</title>
6+
</head>
7+
<body>
8+
<h1>hello world</h1>
9+
</body>
10+
</html>

readFile.py

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
from time import sleep
1+
# from time import sleep
2+
# from selenium import webdriver
3+
#
4+
# def getFile(url):
5+
# #实例化一个浏览器驱动
6+
# chrome = webdriver.Chrome()
7+
#
8+
# #访问页面
9+
# chrome.get(url)
10+
# #捕获元素
11+
#
12+
# texts = chrome.find_elements_by_xpath("//div[@class='content']/p")
13+
# for t in texts:
14+
# print(t.text)
15+
# sleep(1)
16+
# next_url = chrome.find_elements_by_xpath("//a[@class='nextchapter']")
17+
# if next_url:
18+
# next_urls = next_url[0].get_attribute("href")
19+
# getFile(next_urls)
20+
# else:
21+
# chrome.close()
22+
# return
23+
# #关闭浏览器
24+
225
from selenium import webdriver
26+
from selenium.webdriver.common.keys import Keys
27+
from time import sleep
328

4-
def getFile(url):
5-
#实例化一个浏览器驱动
29+
def getFile(Url):
630
chrome = webdriver.Chrome()
31+
chrome.get(Url)
32+
texts = chrome.find_elements_by_xpath("//div[@id='content']")
33+
for t in texts:
34+
with open("xiaoshuo.txt","a") as f:
35+
f.write(t.text)
36+
sleep(5)
37+
chrome.find_element_by_id("banner").send_keys(Keys.RIGHT)
38+
sleep(25)
739

8-
#访问页面
9-
chrome.get(url)
10-
#捕获元素
40+
Url = "https://www.biquga.com/14_14318/3654877.html"
41+
getFile(Url)
1142

12-
texts = chrome.find_elements_by_xpath("//div[@class='content']/p")
13-
for t in texts:
14-
print(t.text)
15-
sleep(1)
16-
next_url = chrome.find_elements_by_xpath("//a[@class='nextchapter']")
17-
if next_url:
18-
next_urls = next_url[0].get_attribute("href")
19-
getFile(next_urls)
20-
else:
21-
chrome.close()
22-
return
23-
#关闭浏览器

0 commit comments

Comments
 (0)