python爬蟲抓取資訊 urllib

2021-09-24 10:19:36 字數 1475 閱讀 2515

自己晚上寫的 本來抓取的是匯率 沒寫完 唉 路還長 繼續走

import requests

import urllib.request

import urllib.request

import re

import datetime

def get_headers():

'''定義請求頭 換著請求頭進行爬取'''

headers =

return headers

def get_ip():

'''**ip 換著位址進行爬取資訊'''

pass

def grab_info():

'''抓取位址'''

url = ''

return url

def get_url_address(url):

'''處理請求位址,或者翻頁

返回的資訊可以是json資料

使用**ip時要跟換方法使用 可以提前寫好

'''headers = get_headers()

request = urllib.request.request(url, headers=headers)

return request

proxy_handler = urllib.request.proxyhandler()

opener = urllib.request.build_opener(proxy_handler)

def get_html(request):

'''進行響應,獲取資料'''

repsonse = urllib.request.urlopen(request)

html = repsonse.read().decode('utf-8')

return html

def handle_data(html):

'''利用xpath re 進行解析'''

need_data = dict()

print(html)

def need_info():

'''儲存資料 可以存入**等 重新調取資料'''

pass

def main():

'''主程式 可以設定死迴圈 來進行不斷抓取資料'''

url = grab_info()

request = get_url_address(url=url)

html = get_html(request =request)

handle_data(html = html)

if __name__ == '__main__':

start_time = datetime.datetime.now()

main()

end_time = datetime.datetime.now()

print('爬取時間'.format(time = end_time-start_time))

python 網頁抓取資訊

目標 從下面這個網頁抓取前10頁ip 埠 運營商 位址 最後檢測時間並存入mysql資料庫 匯入需要使用到的模組 class huoqu 讀入資料 def init self self.num 1 for i in range 10 獲取網頁資訊 response requests.get i se...

python爬蟲 抓取烏雲廠商url

目標 烏雲網是國內最大最權威的安全平台,所以烏雲網的註冊廠商都是業較有影響力的廠商,我們的最終目的是通過烏雲網拿到所有廠商的url,即主站網域名稱,隨後呼叫subdomainsbrute能批量暴力掃瞄子網域名稱,最後將所有得到的子網域名稱通過awvs漏掃介面批量掃瞄,從而達到了批量 全面掃瞄國內 巨...

python 爬蟲實現網頁資訊抓取

首先實現關於網頁解析 讀取等操作我們要用到以下幾個模組 import urllib import urllib2 import re def test f urllib.urlopen while true firstline f.readline print firstline 我們大概要做幾件事...