日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
GitHub超級火!任意爬取,超全開源爬蟲工具箱

最近國內(nèi)一位開發(fā)者在 GitHub 上開源了個集眾多數(shù)據(jù)源于一身的爬蟲工具箱——InfoSpider,一不小心就火了?。。?/p>

現(xiàn)在一般網(wǎng)站都有反爬蟲機制,對于愛爬蟲的朋友來說,想爬蟲些數(shù)據(jù),做下數(shù)據(jù)分析。是越來越難了。不過最近我們,發(fā)現(xiàn)一個超寶藏的爬蟲工具箱。

這個爬蟲工具箱有多火呢?

開源沒幾天就登上GitHub周榜第四,標星1.3K,累計分支 172 個。同時作者已經(jīng)開源了所有的項目代碼及使用文檔,并且在B站上還有使用視頻講解。

項目代碼:

https://github.com/kangvcar/InfoSpider

項目使用文檔:

https://infospider.vercel.app

項目視頻演示:

https://www.bilibili.com/video/BV14f4y1R7oF/

在這樣一個信息爆炸的時代,每個人都有很多個賬號,賬號一多就會出現(xiàn)這么一個情況:個人數(shù)據(jù)分散在各種各樣的公司之間,就會形成數(shù)據(jù)孤島,多維數(shù)據(jù)無法融合,這個項目可以幫你將多維數(shù)據(jù)進行融合并對個人數(shù)據(jù)進行分析,這樣你就可以更直觀、深入了解自己的信息。

InfoSpider 是一個集眾多數(shù)據(jù)源于一身的爬蟲工具箱,旨在安全快捷的幫助用戶拿回自己的數(shù)據(jù),工具代碼開源,流程透明,并提供數(shù)據(jù)分析功能,基于用戶數(shù)據(jù)生成圖表文件。

目前支持數(shù)據(jù)源包括GitHub、QQ郵箱、網(wǎng)易郵箱、阿里郵箱、新浪郵箱、Hotmail郵箱、Outlook郵箱、京東、淘寶、支付寶、中國移動、中國聯(lián)通、中國電信、知乎、嗶哩嗶哩、網(wǎng)易云音樂、QQ好友、QQ群、生成朋友圈相冊、瀏覽器瀏覽歷史、12306、博客園、CSDN博客、開源中國博客、簡書。

根據(jù)創(chuàng)建者介紹,InfoSpider 具有以下特性:

  • 安全可靠:本項目為開源項目,代碼簡潔,所有源碼可見,本地運行,安全可靠。
  • 使用簡單:提供 GUI 界面,只需點擊所需獲取的數(shù)據(jù)源并根據(jù)提示操作即可。
  • 結(jié)構(gòu)清晰:本項目的所有數(shù)據(jù)源相互獨立,可移植性高,所有爬蟲腳本在項目的 Spiders 文件下。
  • 數(shù)據(jù)源豐富:本項目目前支持多達24+個數(shù)據(jù)源,持續(xù)更新。
  • 數(shù)據(jù)格式統(tǒng)一:爬取的所有數(shù)據(jù)都將存儲為json格式,方便后期數(shù)據(jù)分析。
  • 個人數(shù)據(jù)豐富:本項目將盡可能多地為你爬取個人數(shù)據(jù),后期數(shù)據(jù)處理可根據(jù)需要刪減。
  • 數(shù)據(jù)分析:本項目提供個人數(shù)據(jù)的可視化分析,目前僅部分支持。

InfoSpider使用起來也非常簡單,你只需要安裝python3和Chrome瀏覽器,運行 python3 main.py,在打開的窗口點擊數(shù)據(jù)源按鈕, 根據(jù)提示選擇數(shù)據(jù)保存路徑,接著輸入賬號密碼,就會自動爬取數(shù)據(jù),根據(jù)下載的目錄就可以查看爬下來的數(shù)據(jù)。

依賴安裝

  • 安裝python3和Chrome瀏覽器
  • 安裝與Chrome瀏覽器相同版本的驅(qū)動
  • 安裝依賴庫 ./install_deps.sh (Windows下只需pip install -r requirements.txt)

工具運行

  • 進入 tools 目錄
  • 運行 python3 main.py
  • 在打開的窗口點擊數(shù)據(jù)源按鈕, 根據(jù)提示選擇數(shù)據(jù)保存路徑
  • 彈出的瀏覽器輸入用戶密碼后會自動開始爬取數(shù)據(jù), 爬取完成瀏覽器會自動關(guān)閉

在對應的目錄下可以查看下載下來的數(shù)據(jù)(xxx.json), 數(shù)據(jù)分析圖表(xxx.html)

作者認為該項目的最大潛力在于能把多維數(shù)據(jù)進行融合并對個人數(shù)據(jù)進行分析,是個人數(shù)據(jù)效益最大化。

當然如果你想自己去練習和學習爬蟲,作者也開源了所有的爬取代碼,非常適合實戰(zhàn)。

舉個例子,比如爬取taobao的:

 
 
 
 
  1. import json 
  2.  
  3. import random 
  4.  
  5. import time 
  6.  
  7. import sys 
  8.  
  9. import os 
  10.  
  11. import requests 
  12.  
  13. import numpy as np 
  14.  
  15. import math 
  16.  
  17. from lxml import etree 
  18.  
  19. from pyquery import PyQuery as pq 
  20.  
  21. from selenium import webdriver 
  22.  
  23. from selenium.webdriver import ChromeOptions 
  24.  
  25. from selenium.webdriver.common.by import By 
  26.  
  27. from selenium.webdriver.support import expected_conditions as EC 
  28.  
  29. from selenium.webdriver.support.wait import WebDriverWait 
  30.  
  31. from selenium.webdriver import ChromeOptions, ActionChains 
  32.  
  33. from tkinter.filedialog import askdirectory 
  34.  
  35. from tqdm import trange 
  36.  
  37.  
  38.  
  39. def ease_out_quad(x): 
  40.  
  41. return 1 - (1 - x) * (1 - x) 
  42.  
  43. def ease_out_quart(x): 
  44.  
  45. return 1 - pow(1 - x, 4) 
  46.  
  47. def ease_out_expo(x): 
  48.  
  49. if x == 1: 
  50.  
  51. return 1 
  52.  
  53. else: 
  54.  
  55. return 1 - pow(2, -10 * x) 
  56.  
  57. def get_tracks(distance, seconds, ease_func): 
  58.  
  59. tracks = [0] 
  60.  
  61. offsets = [0] 
  62.  
  63. for t in np.arange(0.0, seconds, 0.1): 
  64.  
  65. ease = globals()[ease_func] 
  66.  
  67. offset = round(ease(t / seconds) * distance) 
  68.  
  69. tracks.append(offset - offsets[-1]) 
  70.  
  71. offsets.append(offset) 
  72.  
  73. return offsets, tracks 
  74.  
  75. def drag_and_drop(browser, offset=26.5): 
  76.  
  77. knob = browser.find_element_by_id('nc_1_n1z') 
  78.  
  79. offsets, tracks = get_tracks(offset, 12, 'ease_out_expo') 
  80.  
  81. ActionChains(browser).click_and_hold(knob).perform() 
  82.  
  83. for x in tracks: 
  84.  
  85. ActionChains(browser).move_by_offset(x, 0).perform() 
  86.  
  87. ActionChains(browser).pause(0.5).release().perform() 
  88.  
  89. def gen_session(cookie): 
  90.  
  91. session = requests.session() 
  92.  
  93. cookie_dict = {} 
  94.  
  95. list = cookie.split(';') 
  96.  
  97. for i in list: 
  98.  
  99. try: 
  100.  
  101. cookie_dict[i.split('=')[0]] = i.split('=')[1] 
  102.  
  103. except IndexError: 
  104.  
  105. cookie_dict[''] = i 
  106.  
  107. requests.utils.add_dict_to_cookiejar(session.cookies, cookie_dict) 
  108.  
  109. return session 
  110.  
  111. class TaobaoSpider(object): 
  112.  
  113. def __init__(self, cookies_list): 
  114.  
  115. self.path = askdirectory(title='選擇信息保存文件夾') 
  116.  
  117. if str(self.path) == "": 
  118.  
  119. sys.exit(1) 
  120.  
  121. self.headers = { 
  122.  
  123. 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36', 
  124.  
  125.  
  126. option = ChromeOptions() 
  127.  
  128. option.add_experimental_option('excludeSwitches', ['enable-automation']) 
  129.  
  130. option.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) # 不加載圖片,加快訪問速度 
  131.  
  132. option.add_argument('--headless') 
  133.  
  134. self.driver = webdriver.Chrome(options=option) 
  135.  
  136. self.driver.get('https://i.taobao.com/my_taobao.htm') 
  137.  
  138. for i in cookies_list: 
  139.  
  140. self.driver.add_cookie(cookie_dict=i) 
  141.  
  142. self.driver.get('https://i.taobao.com/my_taobao.htm') 
  143.  
  144. self.wait = WebDriverWait(self.driver, 20) # 超時時長為10s 
  145.  
  146. # 模擬向下滑動瀏覽 
  147.  
  148. def swipe_down(self, second): 
  149.  
  150. for i in range(int(second / 0.1)): 
  151.  
  152. # 根據(jù)i的值,模擬上下滑動 
  153.  
  154. if (i % 2 == 0): 
  155.  
  156. js = "var q=document.documentElement.scrollTop=" + str(300 + 400 * i) 
  157.  
  158. else: 
  159.  
  160. js = "var q=document.documentElement.scrollTop=" + str(200 * i) 
  161.  
  162. self.driver.execute_script(js) 
  163.  
  164. time.sleep(0.1) 
  165.  
  166. js = "var q=document.documentElement.scrollTop=100000" 
  167.  
  168. self.driver.execute_script(js) 
  169.  
  170. time.sleep(0.1) 
  171.  
  172. # 爬取淘寶 我已買到的寶貝商品數(shù)據(jù), pn 定義爬取多少頁數(shù)據(jù) 
  173.  
  174. def crawl_good_buy_data(self, pn=3): 
  175.  
  176. # 對我已買到的寶貝商品數(shù)據(jù)進行爬蟲 
  177.  
  178. self.driver.get("https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm") 
  179.  
  180. # 遍歷所有頁數(shù) 
  181.  
  182.  
  183.  
  184. for page in trange(1, pn): 
  185.  
  186. data_list = [] 
  187.  
  188. # 等待該頁面全部已買到的寶貝商品數(shù)據(jù)加載完畢 
  189.  
  190. good_total = self.wait.until( 
  191.  
  192. EC.presence_of_element_located((By.CSS_SELECTOR, '#tp-bought-root > div.js-order-container'))) 
  193.  
  194. # 獲取本頁面源代碼 
  195.  
  196. html = self.driver.page_source 
  197.  
  198. # pq模塊解析網(wǎng)頁源代碼 
  199.  
  200. doc = pq(html) 
  201.  
  202. # # 存儲該頁已經(jīng)買到的寶貝數(shù)據(jù) 
  203.  
  204. good_items = doc('#tp-bought-root .js-order-container').items() 
  205.  
  206. # 遍歷該頁的所有寶貝 
  207.  
  208. for item in good_items: 
  209.  
  210. # 商品購買時間、訂單號 
  211.  
  212. good_time_and_id = item.find('.bought-wrapper-mod__head-info-cell___29cDO').text().replace('\n', "").replace('\r', "") 
  213.  
  214. # 商家名稱 
  215.  
  216. # good_merchant = item.find('.seller-mod__container___1w0Cx').text().replace('\n', "").replace('\r', "") 
  217.  
  218. good_merchant = item.find('.bought-wrapper-mod__seller-container___3dAK3').text().replace('\n', "").replace('\r', "") 
  219.  
  220. # 商品名稱 
  221.  
  222. # good_name = item.find('.sol-mod__no-br___1PwLO').text().replace('\n', "").replace('\r', "") 
  223.  
  224. good_name = item.find('.sol-mod__no-br___3Ev-2').text().replace('\n', "").replace('\r', "") 
  225.  
  226. # 商品價格 
  227.  
  228. good_price = item.find('.price-mod__price___cYafX').text().replace('\n', "").replace('\r', "") 
  229.  
  230. # 只列出商品購買時間、訂單號、商家名稱、商品名稱 
  231.  
  232. # 其余的請自己實踐獲取 
  233.  
  234. data_list.append(good_time_and_id) 
  235.  
  236. data_list.append(good_merchant) 
  237.  
  238. data_list.append(good_name) 
  239.  
  240. data_list.append(good_price) 
  241.  
  242. #print(good_time_and_id, good_merchant, good_name) 
  243.  
  244. #file_path = os.path.join(os.path.dirname(__file__) + '/user_orders.json') 
  245.  
  246. # file_path = "../Spiders/taobao/user_orders.json" 
  247.  
  248. json_str = json.dumps(data_list) 
  249.  
  250. with open(self.path + os.sep + 'user_orders.json', 'a') as f: 
  251.  
  252. f.write(json_str) 
  253.  
  254. # print('\n\n') 
  255.  
  256. # 大部分人被檢測為機器人就是因為進一步模擬人工操作 
  257.  
  258. # 模擬人工向下瀏覽商品,即進行模擬下滑操作,防止被識別出是機器人 
  259.  
  260. # 隨機滑動延時時間 
  261.  
  262. swipe_time = random.randint(1, 3) 
  263.  
  264. self.swipe_down(swipe_time) 
  265.  
  266. # 等待下一頁按鈕 出現(xiàn) 
  267.  
  268. good_total = self.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, '.pagination-next'))) 
  269.  
  270. good_total.click() 
  271.  
  272. time.sleep(2) 
  273.  
  274. # while 1: 
  275.  
  276. # time.sleep(0.2) 
  277.  
  278. # try: 
  279.  
  280. # good_total = self.driver.find_element_by_xpath('//li[@title="下一頁"]') 
  281.  
  282. # break 
  283.  
  284. # except: 
  285.  
  286. # continue 
  287.  
  288. # # 點擊下一頁按鈕 
  289.  
  290. # while 1: 
  291.  
  292. # time.sleep(2) 
  293.  
  294. # try: 
  295.  
  296. # good_total.click() 
  297.  
  298. # break 
  299.  
  300. # except Exception: 
  301.  
  302. # pass 
  303.  
  304. # 收藏寶貝 傳入爬幾頁 默認三頁 https://shoucang.taobao.com/nodejs/item_collect_chunk.htm?ifAllTag=0&tab=0&tagId=&categoryCount=0&type=0&tagName=&categoryName=&needNav=false&startRow=60 
  305.  
  306. def get_choucang_item(self, page=3): 
  307.  
  308. url = 'https://shoucang.taobao.com/nodejs/item_collect_chunk.htm?ifAllTag=0&tab=0&tagId=&categoryCount=0&type=0&tagName=&categoryName=&needNav=false&startRow={}' 
  309.  
  310. pn = 0 
  311.  
  312. json_list = [] 
  313.  
  314. for i in trange(page): 
  315.  
  316. self.driver.get(url.format(pn)) 
  317.  
  318. pn += 30 
  319.  
  320. html_str = self.driver.page_source 
  321.  
  322. if html_str == '': 
  323.  
  324. break 
  325.  
  326. if '登錄' in html_str: 
  327.  
  328. raise Exception('登錄') 
  329.  
  330. obj_list = etree.HTML(html_str).xpath('//li') 
  331.  
  332. for obj in obj_list: 
  333.  
  334. item = {} 
  335.  
  336. item['title'] = ''.join([i.strip() for i in obj.xpath('./div[@class="img-item-title"]//text()')]) 
  337.  
  338. item['url'] = ''.join([i.strip() for i in obj.xpath('./div[@class="img-item-title"]/a/@href')]) 
  339.  
  340. item['price'] = ''.join([i.strip() for i in obj.xpath('./div[@class="price-container"]//text()')]) 
  341.  
  342. if item['price'] == '': 
  343.  
  344. item['price'] = '失效' 
  345.  
  346. json_list.append(item) 
  347.  
  348. # file_path = os.path.join(os.path.dirname(__file__) + '/shoucang_item.json') 
  349.  
  350. json_str = json.dumps(json_list) 
  351.  
  352. with open(self.path + os.sep + 'shoucang_item.json', 'w') as f: 
  353.  
  354. f.write(json_str) 
  355.  
  356. # 瀏覽足跡 傳入爬幾頁 默認三頁 https://shoucang.taobao.com/nodejs/item_collect_chunk.htm?ifAllTag=0&tab=0&tagId=&categoryCount=0&type=0&tagName=&categoryName=&needNav=false&startRow=60 
  357.  
  358. def get_footmark_item(self, page=3): 
  359.  
  360. url = 'https://www.taobao.com/markets/footmark/tbfoot' 
  361.  
  362. self.driver.get(url) 
  363.  
  364. pn = 0 
  365.  
  366. item_num = 0 
  367.  
  368. json_list = [] 
  369.  
  370. for i in trange(page): 
  371.  
  372. html_str = self.driver.page_source 
  373.  
  374. obj_list = etree.HTML(html_str).xpath('//div[@class="item-list J_redsList"]/div')[item_num:] 
  375.  
  376. for obj in obj_list: 
  377.  
  378. item_num += 1 
  379.  
  380. item = {} 
  381.  
  382. item['date'] = ''.join([i.strip() for i in obj.xpath('./@data-date')]) 
  383.  
  384. item['url'] = ''.join([i.strip() for i in obj.xpath('./a/@href')]) 
  385.  
  386. item['name'] = ''.join([i.strip() for i in obj.xpath('.//div[@class="title"]//text()')]) 
  387.  
  388. item['price'] = ''.join([i.strip() for i in obj.xpath('.//div[@class="price-box"]//text()')]) 
  389.  
  390. json_list.append(item) 
  391.  
  392. self.driver.execute_script('window.scrollTo(0,1000000)') 
  393.  
  394. # file_path = os.path.join(os.path.dirname(__file__) + '/footmark_item.json') 
  395.  
  396. json_str = json.dumps(json_list) 
  397.  
  398. with open(self.path + os.sep + 'footmark_item.json', 'w') as f: 
  399.  
  400. f.write(json_str) 
  401.  
  402. # 地址 
  403.  
  404. def get_addr(self): 
  405.  
  406. url = 'https://member1.taobao.com/member/fresh/deliver_address.htm' 
  407.  
  408. self.driver.get(url) 
  409.  
  410. html_str = self.driver.page_source 
  411.  
  412. obj_list = etree.HTML(html_str).xpath('//tbody[@class="next-table-body"]/tr') 
  413.  
  414. data_list = [] 
  415.  
  416. for obj in obj_list: 
  417.  
  418. item = {} 
  419.  
  420. item['name'] = obj.xpath('.//td[1]//text()') 
  421.  
  422. item['area'] = obj.xpath('.//td[2]//text()') 
  423.  
  424. item['detail_area'] = obj.xpath('.//td[3]//text()') 
  425.  
  426. item['youbian'] = obj.xpath('.//td[4]//text()') 
  427.  
  428. item['mobile'] = obj.xpath('.//td[5]//text()') 
  429.  
  430. data_list.append(item) 
  431.  
  432. # file_path = os.path.join(os.path.dirname(__file__) + '/addr.json') 
  433.  
  434. json_str = json.dumps(data_list) 
  435.  
  436. with open(self.path + os.sep + 'address.json', 'w') as f: 
  437.  
  438. f.write(json_str) 
  439.  
  440.  
  441.  
  442. if __name__ == '__main__': 
  443.  
  444. # pass 
  445.  
  446. cookie_list = json.loads(open('taobao_cookies.json', 'r').read()) 
  447.  
  448. t = TaobaoSpider(cookie_list) 
  449.  
  450. t.get_orders() 
  451.  
  452. # t.crawl_good_buy_data() 
  453.  
  454. # t.get_addr() 
  455.  
  456. # t.get_choucang_item() 
  457.  
  458. # t.get_footmark_item() 

這么優(yōu)秀的倉庫,大家多多給倉庫創(chuàng)建者 star 支持呀!


名稱欄目:GitHub超級火!任意爬取,超全開源爬蟲工具箱
分享地址:http://www.5511xx.com/article/djijeod.html