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"等
https://lodash.com/里 的_.findIndex()就是這樣用的 返回下標(biāo)
如果直接綁二級(jí)域名,那 萬(wàn)一 有人掃描呢。
既然是內(nèi)網(wǎng),可以直接做反代嘛,最簡(jiǎn)單的做法就是改 hosts,或者 Nginx 之類(lèi)的東西設(shè)置一下。
這是一個(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é)果。
因?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)北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專(zhuān)業(yè)的國(guó)家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
北大課工場(chǎng)是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國(guó)家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國(guó)制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國(guó)職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。