在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/ Python問(wèn)答
拽很帥 回答
import unittest
from selenium import webdriver

class TestLogin(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.url = 'http://xxx'
    
    def test_case_1():
        """Test Correct user Name and Password"""
        # code for login
        # assert page title
        pass
        
    def test_case_2():
        """Test Email and Password Fields are blank"""
        pass
        
        ...
        
    def tearDown(self):
        self.driver.quit()  

if __name__ == "__main__":
    unittest.main()
尐潴豬 回答

xpath該這么寫(xiě):"http://span[@class='price J-p-5056201']/text()|//span[@class='price J-p-p-5056201']/text()"

涼汐 回答

不知道為啥換了一個(gè)host就好了,雖然換host,但是還是不知道為啥

墨小白 回答

html里的模板路徑要替換寫(xiě)成"{{STATIC_URL}}css/reset.css"等

毀了心 回答

如果直接綁二級(jí)域名,那 萬(wàn)一 有人掃描呢。

既然是內(nèi)網(wǎng),可以直接做反代嘛,最簡(jiǎn)單的做法就是改 hosts,或者 Nginx 之類(lèi)的東西設(shè)置一下。

拮據(jù) 回答

圖片描述

這是一個(gè)大牛的回答。
學(xué)習(xí)一下思路。

妖妖 回答

我有用過(guò)這個(gè),你不要用他那個(gè)數(shù)據(jù)來(lái)平均等分,而是用另一種方法,比如你的有9份,有3種顏色,那就是分成3份,我目前知道的就這樣解決,我也沒(méi)有找到整數(shù)的api??傊阋昧硪环N方法給他搞成整數(shù)。

薄荷糖 回答

如果你確定你的請(qǐng)求帶上了cookie,那就說(shuō)明進(jìn)入房間跟cookie沒(méi)有關(guān)系。

或者也有可能你傳的cookie失效了,所以沒(méi)有返回你要的結(jié)果;也有可能你操作不對(duì),你的請(qǐng)求根本沒(méi)有把cookie發(fā)出去。

赱丅呿 回答

為什么要弄兩個(gè)spider呢?你完完全全可以在第一個(gè)spider下再寫(xiě)一個(gè)parse_shuping_two啊.


對(duì)你的代碼稍作了修改,可以達(dá)到你的要求(別忘了在settings.py中加上ITEM_PIPELINES = {'ysw.pipelines.YswPipeline': 300}以激活pipeline):
spiders/shuping.py

# -*- coding: utf-8 -*-
import scrapy
from scrapy.http import Request
from ysw.items import YswItem, YswItems
import json
from scrapy import Selector
import re


class ShupingSpider(scrapy.Spider):
    name = 'shuping'
    #allowed_domains = ['www.yousuu.com']
    start_urls = ['http://www.yousuu.com/book/124600']

    #此方法解析評(píng)論第一頁(yè)的一級(jí)書(shū)評(píng)
    def parse(self, response):

        #遍歷每個(gè)一級(jí)書(shū)評(píng),獲得信息
        for r in response.xpath('//*[@id="content"]/div'):
            item = YswItem()

            #發(fā)帖時(shí)間
            item['time'] = r.xpath('string(./div/div/div[1]/div/span[2])').extract_first().strip()

            #獲得贊同數(shù)
            agree = r.xpath('string(./div/div/div[2]/button[1]/span)').extract_first().strip()
            if agree:
                item['agree'] = agree
            else:
                item['agree'] = '0'

            #一級(jí)書(shū)評(píng)內(nèi)容
            item['fir_text'] = r.xpath('string(./div/div/p)').extract_first().replace('\r\n', '').replace(' ', '')

            #二級(jí)評(píng)論數(shù):
            sec_num = r.xpath('string(./div/div/div[2]/button[2]/span)').extract_first().strip()
            if sec_num:
                item['sec_num'] = sec_num

                #獲取二級(jí)評(píng)論url的組成部分cid
                cid = r.xpath('./@cid').extract_first().strip()

                #補(bǔ)全二級(jí)評(píng)論第一頁(yè)的url
                sec_text_url = "http://www.yousuu.com/ajax/getonecomment?render=true&cid={}".format(cid)

                #將每一個(gè)一級(jí)書(shū)評(píng)下的所有二級(jí)書(shū)評(píng)的獲取都交給sp_two.parse
                sec_text_list = []
                yield Request(sec_text_url, meta={'sec_text_list':sec_text_list, 'item':item}, callback=self.parse_shuping_two)
            else:
                item['sec_num'] = '0'
                yield item
        return print('一級(jí)書(shū)評(píng)第一頁(yè)!')

    def parse_shuping_two(self, response):
        items = YswItems()

        # json格式轉(zhuǎn)為python結(jié)構(gòu)數(shù)據(jù)
        jsobj = json.loads(response.body)

        # 從字典中提取html的值,也就是二級(jí)評(píng)論的html格式文本
        html = jsobj['html']

        # 獲得二級(jí)書(shū)評(píng)第一頁(yè)的所有二級(jí)書(shū)評(píng)內(nèi)容,放在列表result中,迭代這個(gè)parse方法時(shí),依次是第2,3,頁(yè)等等
        result = Selector(text=html).xpath('//p/text()').extract()

        # 獲得上一個(gè)Request傳遞過(guò)來(lái)的參數(shù), 第一次是一個(gè)空列表
        sec_text_list = response.meta['sec_text_list']

        # 獲得shuping.parse()傳來(lái)的item
        item = response.meta['item']

        '''每一頁(yè)的二級(jí)評(píng)論內(nèi)容放在一個(gè)列表result中,這個(gè)列表又放在列表sec_text_list中
        二級(jí)書(shū)評(píng)每一頁(yè)的第一個(gè)書(shū)評(píng)都是它的一級(jí)書(shū)評(píng)內(nèi)容,所以從每一頁(yè)新的二級(jí)書(shū)評(píng)從第二個(gè)算起'''
        sec_text_list.extend(result[1:])

        # 判斷二級(jí)評(píng)論是否還有下一頁(yè)
        nextpage = Selector(text=html).xpath('//a[text()="更多回復(fù)"]/@onclick').extract_first()
        if nextpage:
            # 獲得下一頁(yè)的cid
            cid = re.search(r"(.*?)'(.*?)',(.*)", nextpage).group(2)
            # 獲取下一頁(yè)的t
            t = re.search("(.*),(.*?)\)", nextpage).group(2)
            # 組裝二級(jí)評(píng)論下一頁(yè)的url
            next_page_url = "http://www.yousuu.com/ajax/getcommentreply?cid={}&t={}&render=true".format(cid, t)
            # print('next_page_url')
            # 迭代這個(gè)方法繼續(xù)獲得下一頁(yè)的二級(jí)評(píng)論內(nèi)容
            yield Request(next_page_url, meta={'sec_text_list': sec_text_list, 'item': item}, callback=self.parse_shuping_two)
        else:

            items['sec_text'] = sec_text_list
            items['time'] = item['time']
            items['agree'] = item['agree']
            items['sec_num'] = item['sec_num']
            items['fir_text'] = item['fir_text']

            print('已獲取此一級(jí)書(shū)評(píng)的全部二級(jí)書(shū)評(píng)!')

            yield items

pipelines.py

# -*- coding: utf-8 -*-
import os

class YswPipeline(object):
    def process_item(self, item, spider):

        base_dir = os.getcwd()
        file_name = base_dir + '/SP.txt'

        with open(file_name, 'a', encoding='utf-8') as f:
            if item['sec_num'] == '0':
                f.write('時(shí)間:' + item['time'] + '\n'
                    '贊同數(shù):' + item['agree'] + '\n'
                    '二級(jí)評(píng)論數(shù)量:' + item['sec_num'] + '\n'
                    '一級(jí)評(píng)論內(nèi)容:' + item['fir_text'] + '\n\n'
                    )
            else:
                f.write('時(shí)間:' + item['time'] + '\n'
                    '贊同數(shù):' + item['agree'] + '\n'
                    '二級(jí)評(píng)論數(shù)量:' + item['sec_num'] + '\n'
                    '一級(jí)評(píng)論內(nèi)容:' + item['fir_text'] + '\n'
                    '二級(jí)評(píng)論內(nèi)容:' + '\n'.join(item['sec_text']) + '\n\n'
                    )
        return item
悶騷型 回答
# 路徑
# from flask.blueprints import Blueprint
# 然后看下其中的這個(gè)方法
def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
  """A helper method to register a rule (and optionally a view function)
  to the application.  The endpoint is automatically prefixed with the
  blueprint's name.
  """
  if self.url_prefix:
    rule = self.url_prefix + rule
  options.setdefault('subdomain', self.subdomain)
  if endpoint is None:
    endpoint = _endpoint_from_view_func(view_func)
  defaults = self.url_defaults
  if 'defaults' in options:
    defaults = dict(defaults, **options.pop('defaults'))
  self.app.add_url_rule(rule, '%s.%s' % (self.blueprint.name, endpoint),
                        view_func, defaults=defaults, **options)
                        
# 所以你1中的路徑需要訪問(wèn)的是 //api
# 假如 //api 訪問(wèn)不到的話,需要看下你是不是做了類(lèi)似于 /* 的配置
瘋浪 回答

找到問(wèn)題了 mongoengine bug

我使用的是 flask-mongoengine 1.11版本 / mongoengine 版本是0.15

我把mongoengine 升級(jí)到 0.15.3。就好了。好了。。。

以上就沒(méi)出現(xiàn)問(wèn)題了 正常查詢到結(jié)果。

哎呦喂 回答

clipboard.png

因?yàn)镴SON.stringify 會(huì)將對(duì)象中值為undefined 和 function的內(nèi)容丟掉。

如果你想讓JSON.stringify處理后的對(duì)象,保留value為function的部分,需要你顯式的增加一個(gè)replacer來(lái)處理,值為function的對(duì)象,即

JSON.stringify({a:function(){return 1}},function(k,v){
if(typeof v == 'function'){
return v.toString()
}
return v
})

這是JSON.stringify的文檔
https://developer.mozilla.org...

失心人 回答

chrome插件-wappalyzer,當(dāng)然并不會(huì)百分百地顯示全部應(yīng)用的技術(shù)

python:
       selenium自動(dòng)填表單,保存驗(yàn)證碼圖片,點(diǎn)擊查詢
       opencv,去噪分割圖片
       tesseract 識(shí)別驗(yàn)證碼
尐懶貓 回答
#coding:utf-8
import traceback

try:
    1/0
except Exception as e:
    exception = traceback.format_exc()

print("錯(cuò)誤為:\n----\n{}\n----".format(exception))

輸出結(jié)果:

錯(cuò)誤為:
----
Traceback (most recent call last):
  File "file.py", line 5, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero
----

[Finished in 0.1s]

悶騷型 回答

這段網(wǎng)文只道出因?yàn)閣indows沒(méi)有fork, 然後又說(shuō)windows python 用multiprocessing module 實(shí)現(xiàn)多進(jìn)程。。。,實(shí)現(xiàn)了process() 的代碼如果被import而沒(méi)有ifXxxxxxxx的話會(huì)有死循環(huán)。
其實(shí)fork 是unix和linix 實(shí)現(xiàn)多進(jìn)程的方式,跟windows有分別,樓主先去理解fork 吧, 抱歉,我不懂,只是提出個(gè)方向

浪蕩不羈 回答

不建議關(guān)聯(lián)這么多張表,只查詢最基本的信息,其他如部門(mén),主管,頭銜,做出key=>value的樣子,通過(guò)編程語(yǔ)言的foreach添加進(jìn)去。

另外groupby的時(shí)候,【select from (select from t1 group by ) left join t2. 】先分組縮小join的數(shù)據(jù)。
多寫(xiě)幾種sql,比較下執(zhí)行時(shí)間,從中選擇最高效的一種。

神曲 回答
fig = df.plot(title='標(biāo)題', fontsize=20)
fig.axes.title.set_size(20)