中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

西鄉(xiāng)網(wǎng)站開發(fā)長沙seo關(guān)鍵詞排名

西鄉(xiāng)網(wǎng)站開發(fā),長沙seo關(guān)鍵詞排名,wordpress手機版受錢嗎,刷東西網(wǎng)站怎么做通過輸入搜索的關(guān)鍵字,和搜索頁數(shù)范圍,爬出指定文本內(nèi)內(nèi)容并存入到txt文檔。代碼逐行講解。 使用re、res、BeautifulSoup包讀取,代碼已測,可以運行。txt文檔內(nèi)容不亂碼。 import re import requests from bs4 import BeautifulS…

通過輸入搜索的關(guān)鍵字,和搜索頁數(shù)范圍,爬出指定文本內(nèi)內(nèi)容并存入到txt文檔。代碼逐行講解。

使用re、res、BeautifulSoup包讀取,代碼已測,可以運行。txt文檔內(nèi)容不亂碼。

import re
import requests
from bs4 import BeautifulSouptitles = []                                                             #存放文檔標題
urls = []                                                               #存放每個文檔鏈接keyword = input("請輸入想要查找的關(guān)鍵字:")                              
pagenum = input("請輸入想要查找的頁數(shù):")                                        
txt_name = keyword + ":前" + pagenum + "頁內(nèi)容.txt"                        with open(txt_name,'w',encoding='utf-8') as f:                             # 創(chuàng)建txt文件f.write(txt_name + '\r')                                               # 將文件名寫入f.close()# 每頁內(nèi)容單獨爬取
for i in range(1, int(pagenum)+1):                               html = "http://www.ofweek.com/newquery.action?keywords="+keyword+"&type=1&pagenum=" + str(i)         # 根據(jù)關(guān)鍵詞和頁數(shù)生成鏈接resp = requests.get(html)                             # get獲取數(shù)據(jù),訪問拼接后的url                                    resp.encoding = 'gb18030'                             # 讀取中文時不會出現(xiàn)亂碼content = resp.text                  # 拿到網(wǎng)站的數(shù)據(jù),捕獲到的網(wǎng)頁內(nèi)容給content變量# html文件解析,解析響應(yīng)的文件內(nèi)容,html.text 是 HTML 文檔的源代碼,# 'html.parser' 是解析器,用于指定如何解析 HTML 文檔bs = BeautifulSoup(content,'html.parser')#每個標題都存在類名為no-pic的li標簽里面for news in bs.select('div.zx-tl'): url = news.select('a')[0]['href']                     # 提取文章鏈接urls.append(url) title = news.select('a')[0].text                      # 提取文章標題titles.append(title)for i in range(len(urls)):                                    # 遍歷每篇文章的鏈接resp = requests.get(urls[i])resp.encoding='gb18030'content = resp.textbs = BeautifulSoup(content,'html.parser')#文章的內(nèi)容是存在類名為artical-content的div塊里面page_content = bs.select('div.artical-content')[0].textwith open(txt_name,'a',encoding='utf-8') as f:            # 寫入txt文件f.write("\n"+titles[i]+page_content)f.close()print("文件保存成功!")

http://www.risenshineclean.com/news/31509.html

相關(guān)文章:

  • 工藝品做網(wǎng)站網(wǎng)絡(luò)推廣公司
  • wordpress指定用戶隱藏分類廣州seo站內(nèi)優(yōu)化
  • 鄭州做網(wǎng)站推廣價格徐州seo排名收費
  • 廣州網(wǎng)站設(shè)計出名 樂云踐新正規(guī)推廣平臺有哪些
  • 外貿(mào)手機網(wǎng)站seo標題優(yōu)化的心得總結(jié)
  • 網(wǎng)站設(shè)計實例搜狗快速收錄方法
  • 沒有照片怎么做網(wǎng)站教育培訓網(wǎng)站大全
  • 廣西住房建設(shè)廳網(wǎng)站搜索引擎營銷案例分析題
  • 西安住房和城鄉(xiāng)建設(shè)局網(wǎng)站如何讓自己的網(wǎng)站快速被百度收錄
  • 政府網(wǎng)站內(nèi)容建設(shè)方案怎么免費注冊域名
  • 保定網(wǎng)站定制公司seo少女
  • 建站廣告?zhèn)€人網(wǎng)站首頁設(shè)計
  • 邢臺企業(yè)做網(wǎng)站費用哪里可以建網(wǎng)站
  • 瑞麗網(wǎng)站建設(shè)深圳整站seo
  • 湖南做網(wǎng)站 真好磐石網(wǎng)絡(luò)東莞公司網(wǎng)上推廣
  • 網(wǎng)站建設(shè)銷售發(fā)展前景百度指數(shù)關(guān)鍵詞搜索趨勢
  • 英文seo公司seo文章
  • 網(wǎng)站域名使用期怎么去推廣自己的店鋪
  • 做ar的網(wǎng)站搜資源的搜索引擎
  • 婦聯(lián)網(wǎng)站建設(shè)方案搜索歷史記錄
  • 熟人做網(wǎng)站怎么收錢湖南seo服務(wù)電話
  • 東昌網(wǎng)站建設(shè)網(wǎng)站建設(shè)策劃書案例
  • 做網(wǎng)站用的云控制臺活動推廣軟文范例
  • 重慶有什么好玩的旅游景點寧波seo外包優(yōu)化
  • 濟南制作網(wǎng)站的公司哪家好汕頭網(wǎng)站建設(shè)優(yōu)化
  • 網(wǎng)站被墻301怎么做付費推廣平臺有哪些
  • 科威網(wǎng)絡(luò)做網(wǎng)站怎么樣html網(wǎng)頁制作app
  • 網(wǎng)站建設(shè)合同是否繳納印花稅中國網(wǎng)站排名查詢
  • 金寨縣建設(shè)規(guī)劃局網(wǎng)站信息流廣告有哪些投放平臺
  • 做夾具需要知道的幾個網(wǎng)站企業(yè)網(wǎng)站seo方案