最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python獲取整個網(wǎng)頁源碼的方法

 更新時間:2020年08月03日 07:54:00   作者:Ly  
在本篇文章里小編給大家整理的是關(guān)于python獲取整個網(wǎng)頁源碼的方法,需要的朋友們可以參考下。

1、Python中獲取整個頁面的代碼:

import requests
res = requests.get('https://blog.csdn.net/yirexiao/article/details/79092355')
res.encoding = 'utf-8'
print(res.text)

2、運行結(jié)果

p1.jpg

實例擴展:

from bs4 import BeautifulSoup
import time,re,urllib2
t=time.time()
websiteurls={}
def scanpage(url):
 websiteurl=url
 t=time.time()
 n=0
 html=urllib2.urlopen(websiteurl).read()
 soup=BeautifulSoup(html)
 pageurls=[]
 Upageurls={}
 pageurls=soup.find_all("a",href=True)
 for links in pageurls:
  if websiteurl in links.get("href") and links.get("href") not in Upageurls and links.get("href") not in websiteurls:
   Upageurls[links.get("href")]=0
 for links in Upageurls.keys():
  try:
   urllib2.urlopen(links).getcode()
  except:
   print "connect failed"
  else:
   t2=time.time()
   Upageurls[links]=urllib2.urlopen(links).getcode()
   print n,
   print links,
   print Upageurls[links]
   t1=time.time()
   print t1-t2
  n+=1
 print ("total is "+repr(n)+" links")
 print time.time()-t
scanpage(http://news.163.com/)

到此這篇關(guān)于python獲取整個網(wǎng)頁源碼的方法的文章就介紹到這了,更多相關(guān)python如何獲取整個頁面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

甘德县| 清新县| 和平县| 莲花县| 拉孜县| 海兴县| 志丹县| 安平县| 博湖县| 体育| 通许县| 修水县| 苏尼特左旗| 安岳县| 内黄县| 股票| 阿克苏市| 醴陵市| 成武县| 瑞金市| 古浪县| 苍溪县| 绥芬河市| 炎陵县| 容城县| 绥宁县| 靖远县| 武宁县| 彭山县| 化隆| 榕江县| 台东市| 洛川县| 凤凰县| 崇阳县| 无极县| 自治县| 敦化市| 盐源县| 台江县| 连山|