Python筆記從html中提取字段

2021-08-02 07:34:06 字數 994 閱讀 9496

def 

fun():

# url = ''

url_total = '景區&page_size=20&page_num=1®ion=白山市&scope=2&output=json&ak=秘鑰'

response = requests.get(url_total)

url_total_html = response.text

# print(html)

# print(type(html),type(response),html[10:15])

# test1=html["total:"]

# print(test1)

# test2 ='total'

# print(html.find(test2))

total_0=r'[\d]+' #提取所有數字,構成list

result=re.compile(total_0) #將正規表示式編譯成物件 其等價於result=re.compile(r'[\d]+')

total_1=re.findall(result,url_total_html) # 匹配物件,其等價total_1=result.findall(url_total_html)

# print('\n',total_0,type(total_0),len(total_0))

# print(total_1[1],type(total_0[1]))

# print(int(total_1[1]),type(int(total_1[1])))

total_2=int(total_1[1])#提取後其為list,找到對應索引,將str轉int

print(total_2)

#f = open('total—city'

, 'w')

#f.writelines(total_2)

#f.close()

if __name__=='__main__':

fun()

Python練手小程式 從html中提取正文

在github上發現一些很有意思的專案,由於本人作為python的初學者,程式設計 能力相對薄弱,為了加強python的學習,特此利用前輩們的學習知識成果,自己去親自實現。今天練習第0008題,題目如下 先展示一下我的html檔案吧 我打算提取html檔案中的每個題目和摘要,然後儲存在mongodb...

ASP從HTML標籤中提取中文

function delhtml strhtml 做了乙個函式名叫delhtml dim objregexp,stroutput set objregexp new regexp 建立正規表示式 objregexp.ignorecase true 設定是否區分大小寫 objregexp.global...

搜尋之路 c 從html中提取文字

直接封裝成乙個類的,用起來還挺方便的 using system using system.data using system.configuration using system.web using system.web.security using system.web.ui using syst...