Home Php C# Sql C C++ Javascript Python Java Go Android Git Linux Asp.net Django .net Node.js Ios Xcode Cocoa Iphone Mysql Tomcat Mongodb Bash Objective-c Scala Visual-studio Apache Elasticsearch Jar Eclipse Jquery Ruby-on-rails Ruby Rubygems Android-studio Spring Lua Sqlite Emacs Ubuntu Perl Docker Swift Amazon-web-services Svn Html Ajax Xml Java-ee Maven Intellij-idea Rvm Macos Unix Css Ipad Postgresql Css3 Json Windows-server Vue.js Typescript Oracle Hibernate Internet-explorer Github Tensorflow Laravel Symfony Redis Html5 Google-app-engine Nginx Firefox Sqlalchemy Lucene Erlang Flask Vim Solr Webview Facebook Zend-framework Virtualenv Nosql Ide Twitter Safari Flutter Bundle Phonegap Centos Sphinx Actionscript Tornado Register | Login | Edit Tags | New Questions | 繁体 | 简体


10 questions online user: 51

0
votes
answers
26 views
+10

Python Web Scrape Cycle選項卡

0

尋求幫助,以循環訪問網站上的所有選項卡以捕獲所有相關信息。Python Web Scrape Cycle選項卡

在以下站點中,有幾個標籤分別標記爲5x5,5x10x5,10x10等。我不確定如何構造它,以便它會通過選項卡並在我的腳本中編寫循環。感謝您的幫助。

下面是python腳本;

from urllib.request import urlopen as uReq 
from bs4 import BeautifulSoup as soup 
import csv 

urls = [ 
    'https://www.lifestorage.com/storage-units/florida/orlando/32810/610-near-lockhart/?size=5x5' 
] 

filename = 'life_storage.csv' 

f = open(filename, 'a+') 
csv_writer = csv.writer(f) 

headers = ['unit_size', 'unit_type', 'description', 'online_price', 'reg_price', 'store_address', 'store_city', 'store_state', 'store_postalcode' ] 

##unit_size = 5'x10' withouth the ' 
##unit_type = climate controlled or not (this could be blank if non-climate) 
##descirption = the level it's on and type of access. 
##online_price = $##/mo text 
##reg_price = the scratched off $## text 

csv_writer.writerow(headers) 

for my_url in urls: 
    uClient = uReq(my_url) 
    page_html = uClient.read() 
    uClient.close() 
    page_soup = soup(page_html, 'html.parser') 


    store_locator = page_soup.findAll("div", {"itemprop": "address"}) 
    containers = page_soup.findAll("ul", {"id": "spaceList"}) 

    for container in containers: 
     for store_location in store_locator: 
      store_address1 = store_location.find("span", {"itemprop": "streetAddress"}) 
      store_address = store_address1.text 
      store_city1 = store_location.find("span", {"itemprop": "addressLocality"}) 
      store_city = store_city1.text 
      store_state1 = store_location.find("span", {"itemprop": "addressRegion"}) 
      store_state = store_state1.text 
      store_postalcode1 = store_location.find("span", {"itemprop": "postalCode"}) 
      store_postalcode = store_postalcode1.text 
      title_container = container.find("div", {"class": "storesRow"}) 
      unit_size = title_container.text 
      unit_container = container.find("div", {"class": "storesRow"}) 
      unit_type = unit_container.strong.text 
      description_container = container.find("ul", {"class": "features"}) 
      description = description_container.text 
      online_price_container = container.find("div", {"class": "priceBox"}) 
      online_price = online_price_container.strong.text 
      reg_price_container = container.find("div", {"class": "priceBox"}) 
      reg_price = reg_price_container.i.text 

     csv_writer.writerow([unit_size, unit_type, description, online_price, reg_price, store_address, store_city, store_state, store_postalcode]) 

f.close() 

下面是與循環相關的html正文的片段;

//////////\\\Description BOX 
 

 

 

 
<div class="storesRow"> 
 
    <strong> 
 
<a href="/reservation/choose/?store=610&amp;type=1"> 5' x 5'<sup>*</sup> - Climate Controlled </a> 
 
</strong> 
 
    <ul class="features"> 
 
     <li>Indoor access</li> 
 
     <li>Ground Level</li> 
 
    </ul> 
 
</div> 
 

 

 

 
//////////\\\\PRICE BOX 
 

 
<div class="priceBox"> 
 
<strong> 
 

 
             $25/mo 
 

 

 

 

 

 
               <i> $27</i> 
 
</strong> 
 
<em class="pOnly ">Phone &amp; online only</em> 
 
<div class="specialsMessage"> 
 
</div> 
 
</div> 
 

 

 
//////////\\\\ADDRESS BOX 
 

 

 
<div itemprop="address" itemscope="" itemtype="https://schema.org/PostalAddress"> 
 
<em> 
 
<i class="fa fa-map-marker"></i> 
 
<span itemprop="streetAddress">7244 Overland Rd </span> 
 
<span itemprop="addressLocality">Orlando</span>, 
 

 
     <span itemprop="addressRegion">FL</span> 
 
<span itemprop="postalCode">32810</span> 
 
</em> 
 
</div>

電流輸出 enter image description here

所需的輸出 enter image description here

+0

你有什麼期望的輸出? –

+0

@ Paul - 我編輯了目前的輸出結果和我想要的結果。這將遍歷所有選項卡,因此對??於每個新的大小,它將被放在適當標題下的新行中。 –

+0

你有錯誤的注意 - '''writerow()'應該在'for'內部 - 然後它應該把所有項目添加到你的列表中。 – furas

沙发
0
0

你錯了凹痕 - writerow()應該是內for內。

但它可能需要更多工作才能從項目中擠出正確的文本。請參閱代碼。

from urllib.request import urlopen as uReq 
from bs4 import BeautifulSoup as soup 
import csv 

urls = [ 
    'https://www.lifestorage.com/storage-units/florida/orlando/32810/610-near-lockhart/?size=5x5' 
] 

filename = 'life_storage.csv' 

f = open(filename, 'a+') 
csv_writer = csv.writer(f) 

headers = ['unit_size', 'unit_type', 'description', 'online_price', 'reg_price', 'store_address', 'store_city', 'store_state', 'store_postalcode' ] 

##unit_size = 5'x10' withouth the ' 
##unit_type = climate controlled or not (this could be blank if non-climate) 
##descirption = the level it's on and type of access. 
##online_price = $##/mo text 
##reg_price = the scratched off $## text 

csv_writer.writerow(headers) 

for my_url in urls: 
    uClient = uReq(my_url) 
    page_html = uClient.read() 
    uClient.close() 
    page_soup = soup(page_html, 'html.parser') 

    store_location = page_soup.find("div", {"itemprop": "address"}) 

    # need `li` 
    containers = page_soup.find("ul", {"id": "spaceList"}).findAll('li') 
    print('len(containers):', len(containers)) 

    item = store_location.find("span", {"itemprop": "streetAddress"}) 
    store_address = item.text.strip() 

    item = store_location.find("span", {"itemprop": "addressLocality"}) 
    store_city = item.text.strip() 

    item = store_location.find("span", {"itemprop": "addressRegion"}) 
    store_state = item.text.strip() 

    item = store_location.find("span", {"itemprop": "postalCode"}) 
    store_postalcode = item.text.strip() 

    for container in containers: 
     item = container.find("div", {"class": "storesRow"}) 

     if item and item.strong: 
      text = item.strong.text.strip() 
      parts = text.split('-') 
      if len(parts) > 0: 
       unit_size = parts[0].strip().replace('*', "") 
      else: 
       unit_size = '' 

      if len(parts) > 1: 
       unit_type = parts[1].strip() 
      else: 
       unit_type = '' 
     else: 
      continue 

     item = container.find("ul", {"class": "features"}) 

     if item: 
      description = item.text.strip().replace("
", ',') 
     else: 
      description = '' 

     item = container.find("div", {"class": "priceBox"}) 

     if item and item.i: 
      reg_price = item.i.text.strip() 
     else: 
      reg_price = '' 

     if item and item.strong: 
      if item.i: 
       item.i.extract() # remove <i>` 
      online_price = item.strong.text.strip() 
     else: 
      online_price = '' 

     csv_writer.writerow([unit_size, unit_type, description, online_price, reg_price, store_address, store_city, store_state, store_postalcode]) 

f.close() 

結果:

unit_size,unit_type,description,online_price,reg_price,store_address,store_city,store_state,store_postalcode 
5' x 5',Climate Controlled,"Indoor access,Ground Level",$25/mo,$27,7244 Overland Rd,Orlando,FL,32810 
5' x 5',,"Outdoor/Drive-up access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
5' x 10',,"Outdoor/Drive-up access,Ground Level",$46/mo,$50,7244 Overland Rd,Orlando,FL,32810 
10' x 5',Climate Controlled,"Indoor access,Ground Level",$57/mo,$62,7244 Overland Rd,Orlando,FL,32810 
5' x 10',Climate Controlled,"Indoor access,Ground Level",$67/mo,$73,7244 Overland Rd,Orlando,FL,32810 
5' x 10',,"Outdoor/Drive-up access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
5' x 15',Climate Controlled,"Indoor access,Ground Level",$69/mo,$75,7244 Overland Rd,Orlando,FL,32810 
10' x 10',,"Outdoor/Drive-up access,Ground Level",$105/mo,$115,7244 Overland Rd,Orlando,FL,32810 
10' x 10',Climate Controlled,"Indoor access,Ground Level",$105/mo,$115,7244 Overland Rd,Orlando,FL,32810 
10' x 10',Climate Controlled,"Indoor access,Ground Level",$124/mo,$136,7244 Overland Rd,Orlando,FL,32810 
10' x 15',,"Outdoor/Drive-up access,Ground Level",$144/mo,$158,7244 Overland Rd,Orlando,FL,32810 
10' x 16',,"Outdoor/Drive-up access,Ground Level",$145/mo,$159,7244 Overland Rd,Orlando,FL,32810 
10' x 15',Climate Controlled,"Indoor access,Ground Level",$149/mo,$163,7244 Overland Rd,Orlando,FL,32810 
10' x 18',,"Outdoor/Drive-up access,Ground Level",$149/mo,$163,7244 Overland Rd,Orlando,FL,32810 
10' x 15',Climate Controlled,"Indoor access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
10' x 20',,"Outdoor/Drive-up access,Ground Level",$147/mo,$161,7244 Overland Rd,Orlando,FL,32810 
10' x 25',Climate Controlled,"Indoor access,Ground Level",$175/mo,$192,7244 Overland Rd,Orlando,FL,32810 
10' x 20',Climate Controlled,"Indoor access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
10' x 28',,"Outdoor/Drive-up access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
41' x 41',,"Outdoor/Drive-up access,Ground Level",$1400/mo,$1540,7244 Overland Rd,Orlando,FL,32810 
22' x 25',,"Outdoor/Drive-up access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
18' x 38',,"Outdoor/Drive-up access,Ground Level",Check for Availability,,7244 Overland Rd,Orlando,FL,32810 
+0

@ Furas - Dzi?kuj? –

0
votes
answers
33 views
+10

iOS的Sony Remote API應用程序每次嘗試運行時都會崩潰xcode

-1

我剛剛從Sony網站下載了用於IOS的Sony Remote API應用程序。但是我每次運行它時都無法在xcode 9.1上運行它。 xCode意外退出。所有其他應用程序都可以。會是什麼呢?iOS的Sony Remote API應用程序每次嘗試運行時都會崩潰xcode

沙发
0
-1

它只是不能在模擬器上工作,並在設備上正常工作。已解決

0
votes
answers
33 views
+10

讓Android MainActivity等待線程完成

0

我在探索谷歌地圖Android Api v2,我發現了一些麻煩,我正在搞亂!讓Android MainActivity等待線程完成

我正在處理一個包含來自XML文件的路由的LatLng數組。

我想要的應用程序模擬汽車乘坐導入的數據。 (顯示一個簡單的標記,顯示循環中陣列中包含的'當前'位置)

我發現了一種方法,其中將標記從一點移動到另一點。當我使用兩個座標時,它工作得很好,但是當我使用整個數組時,它變得很瘋狂!

我想這是因爲在animateMarker方法中的處理程序

所以,我的問題是,我怎樣才能使主線程等待animateMarker完成,以便正確地看到模擬路線。

謝謝。

下面是代碼:

public class MainActivity extends Activity { 

GoogleMap mMap; 
ArrayList<LatLng> coordinates; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    /** 
    * Here I import the LatLng array from an XML file 
    */ 


    mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); 

    Marker myMarker; 

    myMarker = mMap.addMarker(new MarkerOptions() 
    .position(coordinates.get(0))); 

    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates.get(0),17)); 

    for(int i=0;i<coordinates.size()-1;i++){ 
     animateMarker(myMarker, coordinates.get(i+1), false); 
     mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(coordinates.get(i),17)); 
    } 


} 

/** 
* 
* @param marker 
* @param toPosition 
* @param hideMarker 
* @return 
*/ 
public void animateMarker(final Marker marker, final LatLng toPosition, 
     final boolean hideMarker) { 

    final Handler handler = new Handler(); 
    final long start = SystemClock.uptimeMillis(); 
    final LatLng startLatLng= marker.getPosition(); 
    final long duration = 2000; 

    final Interpolator interpolator = new LinearInterpolator(); 
    handler.post(new Runnable() { 
     @Override 
     public void run() { 
      long elapsed = SystemClock.uptimeMillis() - start; 
      float t = interpolator.getInterpolation((float) elapsed 
        /duration); 
      double lng = t * toPosition.longitude + (1 - t) 
        * startLatLng.longitude; 
      double lat = t * toPosition.latitude + (1 - t) 
        * startLatLng.latitude; 
      marker.setPosition(new LatLng(lat, lng)); 

      if (t < 1.0) { 
       // Post again 16ms later. 
       handler.postDelayed(this, 16); 
      } else { 
       if (hideMarker) { 
        marker.setVisible(false); 
       } else { 
        marker.setVisible(true); 
       } 

      } 
     } 

    }); 

} 

} 
沙发
0
0

使用的AsyncTask

這裏有一個例子

 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { 
     protected Long doInBackground(URL... urls) { 
      int count = urls.length; 
      long totalSize = 0; 
      for (int i = 0; i < count; i++) { 
       totalSize += Downloader.downloadFile(urls[i]); 
       publishProgress((int) ((i/(float) count) * 100)); 
       // Escape early if cancel() is called 
       if (isCancelled()) break; 
      } 
      return totalSize; 
     } 

    protected void onProgressUpdate(Integer... progress) { 
     setProgressPercent(progress[0]); 
    } 

    protected void onPostExecute(Long result) { 
     showDialog("Downloaded " + result + " bytes"); 
    } 
} 

一旦創建了任務執行得很乾脆:

new DownloadFilesTask().execute(url1, url2, url3); 
+0

我嘗試過,但你的意思是?,包括for循環內的doInBackground方法?或者只是用一個thread.sleep填充它? – 2014-10-23 20:12:36

0
votes
answers
17 views
+10

在Python中刪除AJAX加載的網站

1

我已經使用Selenium在以下網站下載了https://www.eex-transparency.com/homepage/power/czech-republic/production/availability/non-usability/non-usability。我正在刮所有的表格數據。它運行良好,但運行該腳本需要相當長的時間。因此,我開始尋找替代方案,並在這裏使用API??向StackOverflow發送了請求到服務器的幾個主題,但經過數小時的嘗試和搜索後,我放棄了,因爲我沒有得到幾件事:在Python中刪除AJAX加載的網站

  • 如何反向工程API發送正確的請求?
  • 我應該使用哪個url鏈接?

這是我想出了:

import json 
import requests 

url = "https://www.eex-transparency.com/ajax/en/navigation/ajaxGetNavi/12" 

data = { 
    "id": "16", 
    "title": "Czech Republic", 
    "url": "https:\/\/www.eex-transparency.com\/homepage\/power\/czech-republic", 
    "class": "country", 
    "description": "", 
    "children": [ 
     { 
     "id": "649", 
     "title": "Production", 
     "url": False, 
     "class": "", 
     "description": "", 
     "children": [ 
      { 
      "id": "650", 
      "title": "Capacity", 
      "url": False, 
      "class": "", 
      "description": "", 
      "children": [ 
       { 
       "id": "651", 
       "title": "Installed Capacity", 
       "url": "https:\/\/www.eex-transparency.com\/homepage\/power\/czech-republic\/production\/capacity\/installed-capacity", 
       "class": "", 
       "description": "" 
       } 
      ] 
      } 
     ] 
     } 
     ]  
    } 


response = requests.get(url, data=data) 
file = response.json() 

在一般情況下,也許有人可以解釋,我應該以什麼措施刮除後網頁,我特別感興趣的是如何找到正確的來自Chrome( - > Inspect - > Network - > XHR)的信息以及如何從後面的信息生成data變量(即我輸入requests)?

沙发
0
0

您可以使用Scrapy

Scrapy,快速的高級別網頁抓取的Python &刮框架。

https://github.com/scrapy/scrapy/

+0

這是怎麼想的?你沒有提供任何細節.. – Aertonas

0
votes
answers
28 views
+10

非常簡單的Scrapy +飛濺項目

0

我正在開發一個非常簡單的Scrapy +飛濺項目來抓取JavaScript網站。這是我的代碼:非常簡單的Scrapy +飛濺項目

splashtest.py:

import scrapy 
from scrapy_splash import SplashRequest 

class SplashSpider(scrapy.Spider): 
    name = 'splash_spider' 

    def start_requests(self): 
     yield SplashRequest(
      url='http://aszx.altervista.org/scrapytest/test.html', 
      callback=self.parse, 
     ) 

    def parse(self, response): 
     self.log('I have just visited ' + response.url) 
     for squadre in response.css('#hello'): 
      yield { 
       'name': squadre.css('::text').extract_first(), 
      } 

settings.py:

BOT_NAME = 'emybet' 

SPIDER_MODULES = ['emybet.spiders'] 
NEWSPIDER_MODULE = 'emybet.spiders' 

SPLASH_URL = 'http://localhost:8050' 
DOWNLOADER_MIDDLEWARES = { 
    'scrapy_splash.SplashCookiesMiddleware': 723, 
    'scrapy_splash.SplashMiddleware': 725, 
    'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware': 810, 
} 
SPIDER_MIDDLEWARES = { 
    'scrapy_splash.SplashDeduplicateArgsMiddleware': 100, 
} 
DUPEFILTER_CLASS = 'scrapy_splash.SplashAwareDupeFilter' 

HTTPCACHE_STORAGE = 'scrapy_splash.SplashAwareFSCacheStorage' 

這是我的迴應:

# scrapy runspider splashtest.py 
2017-11-18 10:10:21 [scrapy] INFO: Scrapy 1.0.5.post4+g4b324a8 started (bot: scrapybot) 
2017-11-18 10:10:21 [scrapy] INFO: Optional features available: ssl, http11 
2017-11-18 10:10:21 [scrapy] INFO: Overridden settings: {} 
2017-11-18 10:10:21 [scrapy] INFO: Enabled extensions: CloseSpider, TelnetConsole, LogStats, CoreStats, SpiderState 
2017-11-18 10:10:22 [scrapy] INFO: Enabled downloader middlewares: HttpAuthMiddleware, DownloadTimeoutMiddleware, UserAgentMiddleware, RetryMiddleware, DefaultHeadersMiddleware, MetaRefreshMiddleware, HttpCompressionMiddleware, RedirectMiddleware, CookiesMiddleware, ChunkedTransferMiddleware, DownloaderStats 
2017-11-18 10:10:22 [scrapy] INFO: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware 
2017-11-18 10:10:22 [scrapy] INFO: Enabled item pipelines: 
2017-11-18 10:10:22 [scrapy] INFO: Spider opened 
2017-11-18 10:10:22 [scrapy] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min) 
2017-11-18 10:10:22 [scrapy] DEBUG: Telnet console listening on 127.0.0.1:6023 
2017-11-18 10:10:22 [scrapy] DEBUG: Crawled (200) <GET http://aszx.altervista.org/scrapytest/test.html> (referer: None) 
2017-11-18 10:10:22 [splash_spider] DEBUG: I have just visited http://aszx.altervista.org/scrapytest/test.html 
2017-11-18 10:10:22 [scrapy] DEBUG: Scraped from <200 http://aszx.altervista.org/scrapytest/test.html> 
{'name': u'No Javascript'} 
2017-11-18 10:10:22 [scrapy] INFO: Closing spider (finished) 
2017-11-18 10:10:22 [scrapy] INFO: Dumping Scrapy stats: 
{'downloader/request_bytes': 252, 
'downloader/request_count': 1, 
'downloader/request_method_count/GET': 1, 
'downloader/response_bytes': 392, 
'downloader/response_count': 1, 
'downloader/response_status_count/200': 1, 
'finish_reason': 'finished', 
'finish_time': datetime.datetime(2017, 11, 18, 9, 10, 22, 975769), 
'item_scraped_count': 1, 
'log_count/DEBUG': 4, 
'log_count/INFO': 7, 
'response_received_count': 1, 
'scheduler/dequeued': 1, 
'scheduler/dequeued/memory': 1, 
'scheduler/enqueued': 1, 
'scheduler/enqueued/memory': 1, 
'start_time': datetime.datetime(2017, 11, 18, 9, 10, 22, 469984)} 
2017-11-18 10:10:22 [scrapy] INFO: Spider closed (finished) 

所以我不沒有得到JavaScript加載的內容。 Splash正在運行,因爲如果我將瀏覽器指向http://localhost:8050,則會看到Splash頁面。

那麼,這是什麼問題?

感謝

沙发
0
0

的問題是,我並沒有開始與COMAND的scrapy項目:「scrapy startproject命令名稱」,但我創建的文件夾和文件自己。

+1

是的,如果你自己創建它(例如,當你複製一個蜘蛛)時,你需要堅持命名對話。 Afaik,因爲你的類名是SplashSpider,名字var應該是'splash' –

0
votes
answers
20 views
+10

Twitter Kit Android - TwitterApiClient轉推不起作用

0

在我的應用程序到目前爲止,我使用Android的Twitter工具包顯示推文(我現在自己的),並有一個轉推按鈕,我正在嘗試(去圖)使用Twitter API客戶端轉發。Twitter Kit Android - TwitterApiClient轉推不起作用

下面是我在這之前提到的鏈接:

1) Twitter REST APIs from Android

2) Twitter Community Discussion on Retweeting using the TwitterApiClient

這是我使用的代碼:

val twApiClient: TwitterApiClient = TwitterCore.getInstance().apiClient 
    tbTweet.setOnMenuItemClickListener { 
     when (it.itemId) { 
      R.id.item_retweet -> { 
       val call: Call<Tweet> = twApiClient.statusesService.retweet(tweetID, true) 
       Log.i("Retweet", if (call.isExecuted) "Successful" else "Failed") 
      } 
     } 
     true 
    } 

我沒有得到任何錯誤,但當我在twitter上轉到我的個人資料頁面時,轉發不顯示。在我提供的第二條鏈接中也提到了同樣的問題,但沒有給出解決方案。

我也註銷執行狀態。它來作爲「失敗」,所以我知道電話retweet()甚至沒有執行。但爲什麼?

有什麼問題,我該如何解決?

沙发
0
0

所以,顯然上面的代碼是不完整的。您必須從retweet(tweetId, true)方法返回的呼叫對象上調用??。然後,您可以撥打onCompleteListener以查看您的轉推是否成功。

0
votes
answers
31 views
+10

Youtube視頻列表,400錯誤代碼

0

我在我的應用程序中使用Youtube API,我試圖從Youtube獲取視頻列表,它工作正常,但它限制在一個列表中的48個視頻由於某些原因,當我試圖讓超過48級的視頻在一個列表中,我得到400錯誤代碼,這裏是我的代碼:Youtube視頻列表,400錯誤代碼

public void Load(final Context context, int start, int end, int category, LoaderVideoListener listener) { 
    try { 
     mVideosNames.clear(); 
     mVideos.clear(); 
     mCategory = category; 
     mStart = start; 
     mEnd = end; 
     mListener = listener; 

     FirebaseDatabase database = FirebaseDatabase.getInstance(); 
     DatabaseReference dataRef = database.getReference(); 
     String child = "Category"; 
     if (mCategory == 1) { 
      child = "category1"; 
     } else if (mCategory == 2) { 
      child = "category2"; 
     } else { 
      child += category; 
     } 
     dataRef.child(child).orderByChild("index").startAt(start).endAt(end).addListenerForSingleValueEvent(new ValueEventListener() { 
      @Override 
      public void onDataChange(DataSnapshot dataSnapshot) { 
       try { 
        StringBuilder videoIds = new StringBuilder(); 

        for (DataSnapshot data : dataSnapshot.getChildren()) { 
         videoIds.append(data.child("YTId").getValue()).append(","); 
        } 

        Network net = new Network(); 
        net.Request(context, URL_1 + videoIds + URL_2, new RequestJsonListiner() { 
         @Override 
         public void OnResponse(String json, boolean isError, String errorDetails) { 
          if (!isError) { 
           try { 
            ParseJsonToVideoYT(json); 
           } catch (JSONException e1) { 
            handleCallBack.obtainMessage(1, e1.getMessage()).sendToTarget(); 
           } 
          } else 
           handleCallBack.obtainMessage(1, errorDetails).sendToTarget(); 
         } 
        }); 

       } catch (Exception e) { 
       } 
      } 

      @Override 
      public void onCancelled(DatabaseError databaseError) { 
       handleCallBack.obtainMessage(1, databaseError.getMessage()).sendToTarget(); 

      } 
     }); 
    } catch (Exception e) { 
    } 
} 
沙发
0
0

400錯誤手段惡劣的請求,從而有出錯了字段參數。另請注意,Youtube API list中的maxResults的最大值爲50.

0
votes
answers
29 views
+10

像Facebook Messenger和WhatsApp這樣的應用程序如何發送和接收消息

-1

嗨,大家好,我正在考慮儘快製作一個API,以供網絡,Android和iOS應用程序使用,我正在考慮在其中實現消息功能。我試圖主要理解Facebook Messenger和WhatsApp等應用程序的「接收」方面。我知道用戶發送消息給服務器的發送方式,它保存在數據庫中,但服務器如何將消息發送到接收設備。某種形式的長期投票?像Facebook Messenger和WhatsApp這樣的應用程序如何發送和接收消息

+0

長輪詢是一個請求模型,你的模型正在尋找的是推動模式。而不是請求事件並處理它們,這個模型獲取事件並處理它們 – Kushan

沙发
0
0

不同的應用傾向於使用不同的服務來接收和發送推送消息。在這裏描述或列出這是一個非常廣泛的話題。下面是在我看來,流行的:

火力地堡雲消息(谷歌的可擴展基礎架構)https://firebase.google.com/docs/cloud-messaging/]

Onesignal [https://onesignal.com/]

PubNub [https://www.pubnub.com/]

還有許多其他的服務在那裏,只是谷歌推消息解決方案更多

+0

因此,大多數應用程序在收到推送通知後,在後臺或前臺運行服務以從服務器下載消息?這似乎是一件合乎邏輯的事情,如果我錯了,請糾正我。 @Kushan – ThatOneQuestionn

+0

是的,你說得很對......如果你看看他們的正在運行的服務,你通常會看到一個正在運行的服務,這是爲了傾聽推送消息 – Kushan

+0

感謝你的回答,真的很感激@Kushan – ThatOneQuestionn

0
votes
answers
26 views
+10

如何爲Travis-CI加密和使用TheMovieDB API_KEY?

-2

我有一個使用MovieDB.org API顯示電影的Android應用程序。如何爲Travis-CI加密和使用TheMovieDB API_KEY?

我已經做了我的加密API_KEY theMovieDB.org爲travic CI如下:

gem install --user travis 
    travis encrypt API_KEY = my_api_key --add 

所以,基本上,它會在.travis.yml一個安全密鑰並將其存儲。 但它似乎沒有工作。我收到以下錯誤:

Execution failed for task ':app:compileDebugJavaWithJavac'. 
    > Compilation failed; see the compiler error output for details. 

我知道我得到這個錯誤,因爲特拉維斯CI想不出我API_KEY。因爲無論何時直接使用我的密鑰,Travis CI都會通過構建。 但不幸的是沒有用上面的代碼加密那個KEY。 我正在做他們在文檔中提到的一切。

這是我.tavis.yml:

language: android 

env: 
    global: 
    secure: some_lengthy_secure_key 

android: 
    components: 
      - platform-tools 
      - build-tools-25.0.3 
      - android-25 
      - extra-android-m2repository 
script: 
    - ./gradlew build 

before_install: 
    - chmod +x gradlew 

branches: 
    only: 
      - master 

這是我的項目:https://github.com/Parag2385/PopularMovies-P

+0

錯誤清楚地表明你的*編譯*失敗。是什麼讓你認爲這與API密鑰有關?只有在程序運行之前,該密鑰纔會被使用。 –

+0

因爲當我在沒有API_KEY的Android studio上編譯我的項目時,它給了我完全相同的錯誤。並且使用API??_key,它可以成功地在仿真器上以及在實際設備上遵循並運行。那麼還有什麼原因可以在那裏? –

+0

而且,當我將我的API_KEY保存在gradle.properties文件中,然後在travis CI上構建時,它不會給我錯誤,而是成功構建傳遞。 但出於安全原因,我無法將我的API_KEY保存在GitHub倉庫中,對不對? –

沙发
0
0

我將與你的診斷似乎並不匹配您所描述的錯誤提意見達成一致。總之:

你能刪除空格周圍travis encrypt API_KEY = my_api_key --add,使之成爲:

travis encrypt 'API_KEY=my_api_key' --org -r Parag2385/PopularMovies-P 

請注意一些其他的變化:

  • 加引號的變量賦值。請檢查密鑰中是否有單引號。
  • 增加了一些事情,以確保正確的端點合適的項目選擇
  • 刪除--add的事情,所以請得到的字符串複製到.travis.yml的適當位置。這是你有機會刪除以前的,錯誤的條目:)
0
votes
answers
37 views
+10

爲什麼我的asp.net身份的用戶會自動註銷

0

我有一個項目,有asp.net MVC和asp.net WebApi。爲什麼我的asp.net身份的用戶會自動註銷

我不知道爲什麼用戶會自動註銷,例如當我關閉瀏覽器和15分鐘後,我發現我需要重新登錄,並且在將用戶重定向到銀行網站以進行付款後,銀行網站再次將用戶重定向到我的網站需要重新登錄。

我用asp.net身份驗證cookie,下面是我StartUp.cs文件代碼:

public class Startup 
{ 
    public string Issuer { get; set; } 
    public void Configuration(IAppBuilder app) 
    { 
     Issuer = "http://localhost:37993/"; 

     ConfigureOAuthTokenGeneration(app); 
     ConfigureOAuthTokenConsumption(app); 

     app.UseCors(CorsOptions.AllowAll); 

     GlobalConfiguration.Configure(WebApiConfig.Register); 
     AreaRegistration.RegisterAllAreas(); 
     //app.UseWebApi(GlobalConfiguration.Configuration); 
     RouteConfig.RegisterRoutes(RouteTable.Routes); 
     //app.UseMvc(RouteConfig.RegisterRoutes); 

     //ConfigureWebApi(GlobalConfiguration.Configuration); 

    } 
    private void ConfigureOAuthTokenGeneration(IAppBuilder app) 
    { 
     app.CreatePerOwinContext(() => new LeitnerContext()); 
     app.CreatePerOwinContext<LeitnerUserManager>(LeitnerUserManager.Create); 
     app.CreatePerOwinContext<LeitnerRoleManager>(LeitnerRoleManager.Create); 

     // Plugin the OAuth bearer JSON Web Token tokens generation and Consumption will be here 

     app.UseCookieAuthentication(new CookieAuthenticationOptions() 
     { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      LoginPath = new Microsoft.Owin.PathString("/User/Login"), 
      ExpireTimeSpan = TimeSpan.FromDays(15), 
      Provider = new CookieAuthenticationProvider 
      { 
       OnApplyRedirect = ctx => 
       { 
        if (!IsForApi(ctx.Request)) 
        { 
         ctx.Response.Redirect(ctx.RedirectUri); 
        } 
       } 
      } 
     }); 
     OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions() 
     { 
      AllowInsecureHttp = true, 
      TokenEndpointPath = new PathString("/api/token"), 
      AccessTokenExpireTimeSpan = TimeSpan.FromDays(15), 
      Provider = new LeitnerOAuthProvider(), 
      AccessTokenFormat = new LeitnerJwtFormat(Issuer), 
     }; 
     app.UseOAuthAuthorizationServer(options); 
     //app.UseJwtBearerAuthentication(options); 
     //app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); 
     //app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 

    } 

    private bool IsForApi(IOwinRequest request) 
    { 
     IHeaderDictionary headers = request.Headers; 
     return ((headers != null) && ((headers["Accept"] == "application/json") || (request.Path.StartsWithSegments(new PathString("/api"))))); 
    } 

    private void ConfigureOAuthTokenConsumption(IAppBuilder app) 
    { 
     var a = AudiencesStore.AudiencesList["LeitnerAudience"]; 
     string audienceId = a.ClientId;// ConfigurationManager.AppSettings["as:AudienceId"]; 
     byte[] audienceSecret = TextEncodings.Base64Url.Decode(a.Base64Secret/*ConfigurationManager.AppSettings["as:AudienceSecret"]*/); 

     // Api controllers with an [Authorize] attribute will be validated with JWT 
     app.UseJwtBearerAuthentication(
      new JwtBearerAuthenticationOptions 
      { 
       AuthenticationMode = AuthenticationMode.Active, 
       AllowedAudiences = new[] { audienceId }, 
       IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[] 
       { 
        new SymmetricKeyIssuerSecurityTokenProvider(Issuer, audienceSecret) 
       } 
      }); 
    } 
} 

有誰知道爲什麼這個問題呢?

+0

您的身份驗證cookie在瀏覽器/提琴手中看起來如何?是否有任何機會會話cookie? –

+0

@mohsen,你的數據庫中的任何機會是securitystamp字段爲空?你能否確認一次 – Webruster

+0

@Webruster db中的securitystamp是什麼?我不知道如何asp.net身份正常工作。任何tutorila正確學習它的地方?我如何使用secutrystamp? – mohsen

沙发
0
1

用戶註銷的原因是由於驗證表單驗證數據和視圖狀態數據時出錯。它可能發生的原因不同,包括在託管服務中使用Web Farm。您應該在您的項目中檢查<machineKey>webconfig

如果沒有<machineKey>webconfig,請嘗試在您的加入webconfig這段代碼<system.web>後:

??

有從那裏你可以生成機鍵一些在線工具。您可以檢查thisthis

您可以從this鏈接瞭解關於機器密鑰的更多信息。

板凳
0
0

也許你ExpireTimeSpan = TimeSpan.FromDays(15)被忽略..

我用的時間跨度是這樣的:

Provider = new CookieAuthenticationProvider 
      { 
      OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
         validateInterval: TimeSpan.FromMinutes(15), 
         regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) 
      }, 
      SlidingExpiration = false, 
      ExpireTimeSpan = TimeSpan.FromMinutes(30) 

增加從配置遺漏碼。 另外,如果您有「記住我」選項,請確保您已在登錄方法中配置它。

var login = await SignInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, shouldLockout: false); 
+0

我用你的解決方案,但它仍然不工作 – mohsen

+0

我忘了一些我在應用中使用的代碼..更新了答案。 –

地板
0
0

「由於此代碼,15分鐘後自動註銷」。

TimeSpan.FromDays(15) 
正常

如果忽略該代碼,你會得到的結果你想要或 ,該值由60 * 24 = 1440( - 19天分鐘)設置。 所以常見的到期時間是一天。 但您將其設置爲15分鐘,以便發生問題。