導航:首頁 > 編程語言 > pythonh2

pythonh2

發布時間:2022-04-14 01:23:16

1. 怎麼用python生成列表[h1,h2,h3,h4],一直到h100

["h%s"%(i+1) for i in range(100)]

2. python中怎麼給編好的程序加一個含有按鈕的界面,按下按鈕開始執行。再來一個結束執行的按鈕

System.Diagnostics.Process.Start(@"你的Phython程序路徑");

3. 如何創建和使用Python CGI腳本

在這個教程里,我們假設Apache web伺服器已經安裝好,並已運行。這篇教程使用的Apache web伺服器(版本2.2.15,用於CentOS發行版6.5)運行在本地主機(127.0.0.1),並且監聽80埠,如下面的Apache指令指定一樣:
ServerName127.0.0.1:80
Listen80
下面舉例中的HTML文件存放在web伺服器上的/var/www/html目錄下,並通過DocumentRoot指令指定(指定網頁文件所在目錄):
DocumentRoot"/var/www/html"
現在嘗試請求URL:http://localhost/page1.html
這將返回web伺服器中下面文件的內容:
/var/www/html/page1.html
為了啟用CGI腳本,我們必須指定CGI腳本在web伺服器上的位置,需要用到ScriptAlias指令:
ScriptAlias/cgi-bin/"/var/www/cgi-bin/"
以上指令表明CGI腳本保存在web伺服器的/var/www/cgi-bin目錄,請求URL里包含/cgi-bin/的將會搜索這個目錄下的CGI腳本。
我們必須還要明確CGI腳本在/var/www/cgi-bin目錄下有執行許可權,還要指定CGI腳本的文件擴展名。使用下面的指令:
<Directory"/var/www/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .py
</Directory>
下面訪問URL:http://localhost/cgi-bin/myscript-1.py
這將會調用web伺服器中下面所示腳本:
/var/www/cgi-bin/myscript-1.py
創建一個CGI腳本
在創建一個Python CGI腳本之前,你需要確認你已經安裝了Python(這通常是默認安裝的,但是安裝版本可能會有所不同)。本篇教程使用的腳本是使用Python版本2.6.6編寫的。你可以通過下面任意一命令(-V和--version參數將顯示所安裝Python的版本號)檢查Python的版本。
$ python -V
$ python --version
如果你的Python CGI腳本要用來處理用戶輸入的數據(從一個web輸入表單),那麼你將需要導入Python cgi模塊。這個模塊可以處理用戶通過web輸入表單輸入的數據。你可以在你的腳本中通過下面的語句導入該腳本:
import cgi
你也必須修改Python CGI腳本的執行許可權,以防止web伺服器不能調用。可以通過下面的命令增加執行許可權:
# chmod o+x myscript-1.py
Python CGI例子
涉及到Python CGI腳本的兩個方案將會在下面講述:
使用Python腳本創建一個網頁
讀取並顯示用戶輸入的數據,並且在網頁上顯示結果
注意:Python cgi模塊在方案2中是必需的,因為這涉及到用戶從web表單輸入數據。
例子1 :使用Python腳本創建一個網頁
對於這個方案,我們將通過創建包含一個單一提交按鈕的網頁/var/www/html/page1.html開始。
<html>
<h1>Test Page 1</h1>
<formname="input"action="/cgi-bin/myscript-1.py"method="get">
<inputtype="submit"value="Submit">
</form>
</html>
當"提交"按鈕被點擊,/var/www/cgi-bin/myscript-1.py腳本將被調用(通過action參數指定)。通過設置方法參數為"get"來指定一個"GET"請求,伺服器將會返回指定的網頁。/var/www/html/page1.html在瀏覽器中的顯示情況如下:

/var/www/cgi-bin/myscript-1.py的內容如下:
#!/usr/bin/python
print"Content-Type: text/html"
print""
print"<html>"
print"<h2>CGI Script Output</h2>"
print"<p>This page was generated by a Python CGI script.</p>"
print"</html>"
第一行聲明表示這是使用 /usr/bin/python命令運行的Python腳本。"Content-Type: text/html"列印語句是必需的,這是為了讓web伺服器知道接受自CGI腳本的輸出類型。其餘的語句用來輸出HTML格式的其餘網頁內容。
當"Submit"按鈕點擊,下面的網頁將返回:

這個例子的要點是你可以決定哪些信息可以被CGI腳本返回。這可能包括日誌文件的內容,當前登陸用戶的列表,或者今天的日期。在你處理時擁有所有python庫的可能性是無窮無盡的。
例子2:讀取並顯示用戶輸入的數據,並將結果顯示在網頁上
對於這個方案,我們將通過創建一個含有三個輸入域和一個提交按鈕的網頁/var/www/html/page2.html開始。
<html>
<h1>Test Page 2</h1>
<formname="input"action="/cgi-bin/myscript-2.py"method="get">
First Name: <inputtype="text"name="firstName"><br>
Last Name: <inputtype="text"name="lastName"><br>
Position: <inputtype="text"name="position"><br>
<inputtype="submit"value="Submit">
</form>
</html>
當"Submit"按鈕點擊,/var/www/cgi-bin/myscript-2.py腳本將被執行(通過action參數指定)。/var/www//html/page2.html顯示在web瀏覽器中的圖片如下所示(注意,三個輸入域已經被填寫好了):

/var/www/cgi-bin/myscript-2.py的內容如下:
#!/usr/bin/python
import cgi
form = cgi.FieldStorage()
print"Content-Type: text/html"
print""
print"<html>"
print"<h2>CGI Script Output</h2>"
print"<p>"
print"The user entered data are:<br>"
print"<b>First Name:</b> "+ form["firstName"].value +"<br>"
print"<b>Last Name:</b> "+ form["lastName"].value +"<br>"
print"<b>Position:</b> "+ form["position"].value +"<br>"
print"</p>"
print"</html>"
正如前面提到,import cgi語句用來確保能夠處理用戶通過web輸入表單輸入的數據。web輸入表單被封裝在一個表單對象中,叫做cgi.FieldStorage對象。一旦開始輸出,"Content-Type: text/html"是必需的,因為web伺服器需要知道接受自CGI腳本的輸出格式。用戶輸入的數據在包含form["firstName"].value,form["lastName"].value,和 form["position"].value的語句中可以得到。那些中括弧中的名稱和/var/www/html/page2.html文本輸入域中定義的名稱參數一致。
當網頁上的"Submit"按鈕被點擊,下面的網頁將被返回。

這個例子的要點就是你可以很容易地讀取並顯示用戶在web表單上輸入的數據。除了以字元串的方式處理數據,你也可以用Python將用戶輸入的數據轉化為可用於數值計算的數字。

4. Python 能不能到函數里才執行實參

通過變通的方式是可以實現的,比如把實參封裝成函數。

Number=lambda:response.xpath('/html/body').re('(?<="proct_no"value=").*?(?=")')[0]

在函數中通過Number()調用


如果解決了您的問題請採納!

如果未解決請繼續追問

5. python正則匹配不到想要的數據,感覺明明是對的啊

items = re.findall(r'',pagecode,re.S)

注意在後面要加上re.S

因為是多行匹配,下面寫了一個只能抓一頁信息的簡陋版- -

-------------------------------------------------------------------------------------------

#coding:utf-8
importurllib2,re
classdown(object):


def__init__(self):
self.user_agent='Mozilla/4.0(compatible;MSIE5.5;WindowsNT)'
self.headers={'User-Agent':self.user_agent}

defgetPage(self):
try:
url='http://hdwan.net'

request=urllib2.Request(url,headers=self.headers)
response=urllib2.urlopen(request)
pageCode=response.read().decode('utf-8')
returnpageCode
excepturllib2.URLError,e:
ifhasattr(e,'reason'):
printu'連接失敗...',e.reason
returnNone


defgetCont(self):
pageCode=self.getPage()
ifnotpageCode:
printu'頁面載入失敗...'
returnNone
items=re.findall('''<h2><ahref="(.*?)"rel="bookmark"target="_blank"title="(.*?)">.*?
</a></h2>''',pageCode,re.S)
foriinitems:
printu'電影名:%s 鏈接:%s '%(i[1],i[0])


if__name__=='__main__':
spider=down()
spider.getCont()

初學者一起加油。。。。

6. 如何用python爬取豆瓣讀書的數據

這兩天爬了豆瓣讀書的十萬條左右的書目信息,用時將近一天,現在趁著這個空閑把代碼總結一下,還是菜鳥,都是用的最簡單最笨的方法,還請路過的大神不吝賜教。
第一步,先看一下我們需要的庫:

import requests #用來請求網頁
from bs4 import BeautifulSoup #解析網頁
import time #設置延時時間,防止爬取過於頻繁被封IP號
import re #正則表達式庫
import pymysql #由於爬取的數據太多,我們要把他存入MySQL資料庫中,這個庫用於連接資料庫
import random #這個庫里用到了產生隨機數的randint函數,和上面的time搭配,使爬取間隔時間隨機

這個是豆瓣的網址:x-sorttags-all
我們要從這里獲取所有分類的標簽鏈接,進一步去爬取裡面的信息,代碼先貼上來:

import requests
from bs4 import BeautifulSoup #導入庫

url="httom/tag/?icn=index-nav"
wb_data=requests.get(url) #請求網址
soup=BeautifulSoup(wb_data.text,"lxml") #解析網頁信息
tags=soup.select("#content > div > div.article > div > div > table > tbody > tr > td > a")
#根據CSS路徑查找標簽信息,CSS路徑獲取方法,右鍵-檢查- selector,tags返回的是一個列表
for tag in tags:
tag=tag.get_text() #將列表中的每一個標簽信息提取出來
helf="hom/tag/"
#觀察一下豆瓣的網址,基本都是這部分加上標簽信息,所以我們要組裝網址,用於爬取標簽詳情頁
url=helf+str(tag)
print(url) #網址組裝完畢,輸出

以上我們便爬取了所有標簽下的網址,我們將這個文件命名為channel,並在channel中創建一個channel字元串,放上我們所有爬取的網址信息,等下爬取詳情頁的時候直接從這里提取鏈接就好了,如下:

channel='''
tag/程序
'''

現在,我們開始第二個程序。


QQ圖片20160915233329.png


標簽頁下每一個圖片的信息基本都是這樣的,我們可以直接從這里提取到標題,作者,出版社,出版時間,價格,評價人數,以及評分等信息(有些外國作品還會有譯者信息),提取方法與提取標簽類似,也是根據CSS路徑提取。
我們先用一個網址來實驗爬取:

url="htt/tag/科技"
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text.encode("utf-8"), "lxml")
tag=url.split("?")[0].split("/")[-1] #從鏈接裡面提取標簽信息,方便存儲
detils=soup.select("#subject_list > ul > li > div.info > div.pub") #抓取作者,出版社信息,稍後我們用spite()函數再將他們分離出來
scors=soup.select("#subject_list > ul > li > div.info > div.star.clearfix > span.rating_nums") #抓取評分信息
persons=soup.select("#subject_list > ul > li > div.info > div.star.clearfix > span.pl") #評價人數
titles=soup.select("#subject_list > ul > li > div.info > h2 > a") #書名
#以上抓取的都是我們需要的html語言標簽信息,我們還需要將他們一一分離出來
for detil,scor,person,title in zip(detils,scors,persons,titles):
#用一個zip()函數實現一次遍歷
#因為一些標簽中有譯者信息,一些標簽中沒有,為避免錯誤,所以我們要用一個try來把他們分開執行
try:
author=detil.get_text().split("/",4)[0].split()[0] #這是含有譯者信息的提取辦法,根據「/」 把標簽分為五部分,然後依次提取出來
yizhe= detil.get_text().split("/", 4)[1]
publish=detil.get_text().split("/", 4)[2]
time=detil.get_text().split("/", 4)[3].split()[0].split("-")[0] #時間我們只提取了出版年份
price=ceshi_priceone(detil) #因為價格的單位不統一,我們用一個函數把他們換算為「元」
scoe=scor.get_text() if True else "" #有些書目是沒有評分的,為避免錯誤,我們把沒有評分的信息設置為空
person=ceshi_person(person) #有些書目的評價人數顯示少於十人,爬取過程中會出現錯誤,用一個函數來處理
title=title.get_text().split()[0]
#當沒有譯者信息時,會顯示IndexError,我們分開處理
except IndexError:
try:
author=detil.get_text().split("/", 3)[0].split()[0]
yizhe="" #將detil信息劃分為4部分提取,譯者信息直接設置為空,其他與上面一樣
publish=detil.get_text().split("/", 3)[1]
time=detil.get_text().split("/", 3)[2].split()[0].split("-")[0]
price=ceshi_pricetwo(detil)
scoe=scor.get_text() if True else ""
person=ceshi_person(person)
title=title.get_text().split()[0]
except (IndexError,TypeError):
continue
#出現其他錯誤信息,忽略,繼續執行(有些書目信息下會沒有出版社或者出版年份,但是數量很少,不影響我們大規模爬取,所以直接忽略)
except TypeError:
continue

#提取評價人數的函數,如果評價人數少於十人,按十人處理
def ceshi_person(person):
try:
person = int(person.get_text().split()[0][1:len(person.get_text().split()[0]) - 4])
except ValueError:
person = int(10)
return person

#分情況提取價格的函數,用正則表達式找到含有特殊字元的信息,並換算為「元」
def ceshi_priceone(price):
price = detil.get_text().split("/", 4)[4].split()
if re.match("USD", price[0]):
price = float(price[1]) * 6
elif re.match("CNY", price[0]):
price = price[1]
elif re.match("A$", price[0]):
price = float(price[1:len(price)]) * 6
else:
price = price[0]
return price
def ceshi_pricetwo(price):
price = detil.get_text().split("/", 3)[3].split()
if re.match("USD", price[0]):
price = float(price[1]) * 6
elif re.match("CNY", price[0]):
price = price[1]
elif re.match("A$", price[0]):
price = float(price[1:len(price)]) * 6
else:
price = price[0]
return price

實驗成功後,我們就可以爬取數據並導入到資料庫中了,以下為全部源碼,特殊情況會用注釋一一說明。

import requests
from bs4 import BeautifulSoup
import time
import re
import pymysql
from channel import channel #這是我們第一個程序爬取的鏈接信息
import random

def ceshi_person(person):
try:
person = int(person.get_text().split()[0][1:len(person.get_text().split()[0]) - 4])
except ValueError:
person = int(10)
return person

def ceshi_priceone(price):
price = detil.get_text().split("/", 4)[4].split()
if re.match("USD", price[0]):
price = float(price[1]) * 6
elif re.match("CNY", price[0]):
price = price[1]
elif re.match("A$", price[0]):
price = float(price[1:len(price)]) * 6
else:
price = price[0]
return price

def ceshi_pricetwo(price):
price = detil.get_text().split("/", 3)[3].split()
if re.match("USD", price[0]):
price = float(price[1]) * 6
elif re.match("CNY", price[0]):
price = price[1]
elif re.match("A$", price[0]):
price = float(price[1:len(price)]) * 6
else:
price = price[0]
return price


#這是上面的那個測試函數,我們把它放在主函數中
def mains(url):
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text.encode("utf-8"), "lxml")
tag=url.split("?")[0].split("/")[-1]
detils=soup.select("#subject_list > ul > li > div.info > div.pub")
scors=soup.select("#subject_list > ul > li > div.info > div.star.clearfix > span.rating_nums")
persons=soup.select("#subject_list > ul > li > div.info > div.star.clearfix > span.pl")
titles=soup.select("#subject_list > ul > li > div.info > h2 > a")
for detil,scor,person,title in zip(detils,scors,persons,titles):
l = [] #建一個列表,用於存放數據
try:
author=detil.get_text().split("/",4)[0].split()[0]
yizhe= detil.get_text().split("/", 4)[1]
publish=detil.get_text().split("/", 4)[2]
time=detil.get_text().split("/", 4)[3].split()[0].split("-")[0]
price=ceshi_priceone(detil)
scoe=scor.get_text() if True else ""
person=ceshi_person(person)
title=title.get_text().split()[0]
except IndexError:
try:
author=detil.get_text().split("/", 3)[0].split()[0]
yizhe=""
publish=detil.get_text().split("/", 3)[1]
time=detil.get_text().split("/", 3)[2].split()[0].split("-")[0]
price=ceshi_pricetwo(detil)
scoe=scor.get_text() if True else ""
person=ceshi_person(person)
title=title.get_text().split()[0]
except (IndexError,TypeError):
continue

except TypeError:
continue
l.append([title,scoe,author,price,time,publish,person,yizhe,tag])
#將爬取的數據依次填入列表中


sql="INSERT INTO allbooks values(%s,%s,%s,%s,%s,%s,%s,%s,%s)" #這是一條sql插入語句
cur.executemany(sql,l) #執行sql語句,並用executemary()函數批量插入資料庫中
conn.commit()

#主函數到此結束


# 將Python連接到MySQL中的python資料庫中
conn = pymysql.connect( user="root",password="123123",database="python",charset='utf8')
cur = conn.cursor()

cur.execute('DROP TABLE IF EXISTS allbooks') #如果資料庫中有allbooks的資料庫則刪除
sql = """CREATE TABLE allbooks(
title CHAR(255) NOT NULL,
scor CHAR(255),
author CHAR(255),
price CHAR(255),
time CHAR(255),
publish CHAR(255),
person CHAR(255),
yizhe CHAR(255),
tag CHAR(255)
)"""
cur.execute(sql) #執行sql語句,新建一個allbooks的資料庫


start = time.clock() #設置一個時鍾,這樣我們就能知道我們爬取了多長時間了
for urls in channel.split():
urlss=[urls+"?start={}&type=T".format(str(i)) for i in range(0,980,20)] #從channel中提取url信息,並組裝成每一頁的鏈接
for url in urlss:
mains(url) #執行主函數,開始爬取
print(url) #輸出要爬取的鏈接,這樣我們就能知道爬到哪了,發生錯誤也好處理
time.sleep(int(format(random.randint(0,9)))) #設置一個隨機數時間,每爬一個網頁可以隨機的停一段時間,防止IP被封
end = time.clock()
print('Time Usage:', end - start) #爬取結束,輸出爬取時間
count = cur.execute('select * from allbooks')
print('has %s record' % count) #輸出爬取的總數目條數

# 釋放數據連接
if cur:
cur.close()
if conn:
conn.close()

這樣,一個程序就算完成了,豆瓣的書目信息就一條條地寫進了我們的資料庫中,當然,在爬取的過程中,也遇到了很多問題,比如標題返回的信息拆分後中會有空格,寫入資料庫中會出現錯誤,所以只截取了標題的第一部分,因而導致資料庫中的一些書名不完整,過往的大神如果有什麼辦法,還請指教一二。
等待爬取的過程是漫長而又欣喜的,看著電腦上一條條信息被刷出來,成就感就不知不覺湧上心頭;然而如果你吃飯時它在爬,你上廁所時它在爬,你都已經爬了個山回來了它還在爬時,便會有點崩潰了,擔心電腦隨時都會壞掉(還是窮學生換不起啊啊啊啊~)
所以,還是要好好學學設置斷點,多線程,以及正則,路漫漫其修遠兮,吾將上下而求索~共勉~

7. 如何用 Python 爬取社交網路

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Author: Administrator
# @Date: 2015-10-31 15:45:27
# @Last Modified by: Administrator
# @Last Modified time: 2015-11-23 16:57:31
import requests
import sys
import json
import re
reload(sys)
sys.setdefaultencoding('utf-8')

#獲取到匹配字元的字元串
def find(pattern,test):
finder = re.search(pattern, test)
start = finder.start()
end = finder.end()
return test[start:end-1]

cookies = {
'_ga':'GA1.2.10sdfsdfsdf', '_za':'8d570b05-b0b1-4c96-a441-faddff34',
'q_c1':'23ddd234234',
'_xsrf':'234id':'"ZTE3NWY2ZTsdfsdfsdfWM2YzYxZmE=|1446435757|"',
'z_c0':'"=|14464e234767|"',
'__utmt':'1', '__utma':'51854390.109883802f8.1417518721.1447917637.144c7922009.4',
'__utmb':'518542340.4.10.1447922009', '__utmc':'51123390', '__utmz':'5185435454sdf06.1.1.utmcsr=hu.com|utmcgcn=(referral)|utmcmd=referral|utmcct=/',
'__utmv':'51854340.1d200-1|2=registration_date=2028=1^3=entry_date=201330318=1'}

headers = {'user-agent':
'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36',
'referer':'http://www.hu.com/question/following',
'host':'www.hu.com','Origin':'http://www.hu.com',
'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
'Connection':'keep-alive','X-Requested-With':'XMLHttpRequest','Content-Length':'81',
'Accept-Encoding':'gzip,deflate','Accept-Language':'zh-CN,zh;q=0.8','Connection':'keep-alive'
}

#多次訪問之後,其實一載入時載入20個問題,具體參數傳輸就是offset,以20遞增

dicc = {"offset":60}
n=20
b=0

# 與爬取圖片相同的是,往下拉的時候也會發送http請求返回json數據,但是不同的是,像模擬登錄首頁不同的是除了
# 發送form表單的那些東西後,知乎是拒絕了我的請求了,剛開始以為是headers上的攔截,往headers添加瀏覽器
# 訪問是的headers那些信息添加上,發現還是拒絕訪問。

#想了一下,應該是cookie原因。這個載入的請求和模擬登錄首頁不同
#所以補上其他的cookies信息,再次請求,請求成功。
for x in xrange(20,460,20):
n = n+20
b = b+20
dicc['offset'] = x
formdata = {'method':'next','params':'{"offset":20}','_xsrf':''}

#傳輸需要json串,和python的字典是有區別的,需要轉換
formdata['params'] = json.mps(dicc)
# print json.mps(dicc)
# print dicc

circle = requests.post("http://www.hu.com/node/ProfileFollowedQuestionsV2",
cookies=cookies,data=formdata,headers=headers)

#response內容 其實爬過一次之後就大同小異了。 都是
#問題返回的json串格式
# {"r":0,
# "msg": ["<div class=\"zm-profile-section-item zg-clear\">\n
# <span class=\"zm-profile-vote-count\">\n<div class=\"zm-profile-vote-num\">205K<\/div>\n
# <div class=\"zm-profile-vote-type\">\u6d4f\u89c8<\/div>\n
# <\/span>\n<div class=\"zm-profile-section-main\">\n
# <h2 class=\"zm-profile-question\">\n
# <a class=\"question_link\" target=\"_blank\" href=\"\/question\/21719532\">
# \u4ec0\u4e48\u4fc3\u4f7f\u4f60\u8d70\u4e0a\u72ec\u7acb\u5f00\u53d1\u8005\u4e4b\u8def\uff1f<\/a>\n
# <\/h2>\n<div class=\"meta zg-gray\">\n<a data-follow=\"q:link\" class=\"follow-link zg-unfollow meta-item\"
# href=\"javascript:;\" id=\"sfb-868760\">
# <i class=\"z-icon-follow\"><\/i>\u53d6\u6d88\u5173\u6ce8<\/a>\n<span class=\"zg-bull\">•<\/span>\n63 \u4e2a\u56de\u7b54\n<span class=\"zg-bull\">•<\/span>\n3589 \u4eba\u5173\u6ce8\n<\/div>\n<\/div>\n<\/div>",
# "<div class=\"zm-profile-section-item zg-clear\">\n
# <span class=\"zm-profile-vote-count\">\n
# <div class=\"zm-profile-vote-num\">157K<\/div>\n
# <div class=\"zm-profile-vote-type\">\u6d4f\u89c8<\/div>\n
# <\/span>\n<div class=\"zm-profile-section-main\">\n
# <h2 class=\"zm-profile-question\">\n
# <a class=\"question_link\" target=\"_blank\" href=\"\/question\/31764065\">
# \u672c\u79d1\u6e23\u6821\u7684\u5b66\u751f\u5982\u4f55\u8fdb\u5165\u7f8e\u5e1d\u725b\u6821\u8bfbPhD\uff1f<\/a>\n
# <\/h2>\n<div class=\"meta zg-gray\">\n
# <a data-follow=\"q:link\" class=\"follow-link zg-unfollow meta-item\" href=\"javascript:;\" id=\"sfb-4904877\">
# <i class=\"z-icon-follow\"><\/i>\u53d6\u6d88\u5173\u6ce8<\/a>\n<span class=\"zg-bull\">•
# <\/span>\n112 \u4e2a\u56de\u7b54\n<span class=\"zg-bull\">•<\/span>\n1582 \u4eba\u5173\u6ce8\n
# <\/div>\n<\/div>\n<\/div>"]}
# print circle.content

#同樣json串需要自己 轉換成字典後使用
jsondict = json.loads(circle.text)
msgstr = jsondict['msg']
# print len(msgstr)

#根據自己所需要的提取信息規則寫出正則表達式
pattern = 'question\/.*?/a>'
try:
for y in xrange(0,20):
wholequestion = find(pattern, msgstr[y])
pattern2 = '>.*?<'
finalquestion = find(pattern2, wholequestion).replace('>','')
print str(b+y)+" "+finalquestion

#當問題已經訪問完後再傳參數 拋出異常 此時退出循環
except Exception, e:
print "全部%s個問題" %(b+y)
break

8. Python 製作網頁打不開 直接跳到打開或者保存文件

需要對Lighttpd進行配置,指明py文件是作為cgi程序運行的。
修改配置文件:/etc/lighttpd/lighttpd.conf
在以下小節內添加python內容:
server.moles = ( "mod_cgi", )
cgi.assign = (
".py" => "/usr/bin/python"
)

9. python一個函數qh2(x,y,z),表示從x加到y,每次增加z怎麼處理

包括y的話:

def qh2(x, y, z):

result = 0

for i in range(x, y+1, z):

result += i

return result

閱讀全文

與pythonh2相關的資料

熱點內容
編譯怎麼學 瀏覽:329
數碼管顯示0到9plc編程 瀏覽:665
伺服器是為什麼服務的 瀏覽:765
java定義數據類型 瀏覽:874
安卓pdf手寫 瀏覽:427
什麼是app開發者 瀏覽:284
android鬧鍾重啟 瀏覽:101
程序員失職 瀏覽:518
在雲伺服器怎麼改密碼 瀏覽:586
伺服器pb什麼意思 瀏覽:940
51駕駛員的是什麼app 瀏覽:670
php靜態變數銷毀 瀏覽:886
編程買蘋果電腦 瀏覽:760
flac演算法 瀏覽:497
reactnative與android 瀏覽:663
程序員是干什麼的工作好嗎 瀏覽:258
kbuild編譯ko 瀏覽:469
條件編譯的宏 瀏覽:564
韓語編程語言 瀏覽:646
小程序開發如何租用伺服器 瀏覽:80