一個爬蟲類就可以解決。
yield Request(URL,callback)返回第一次爬取的鏈接。
然后用callback函數(shù)對返回鏈接進行再次爬取,接著再對爬取數(shù)據(jù)處理給item或者繼續(xù)yield Request也行。
callback就是回調(diào)的函數(shù)名。
不用存文檔里,那樣速度太慢了。
例子:類似于這種,有點偽代碼。
class MySpider(scrapy.Spider):
name = 'zhilian_spider'
allowed_domains = ['example.com']
start_urls = [
'http://www.zhaopin.com/citymap.html']
yield scrapy.Request(url, callback=self.parse)
def parse(self, response):
...
yield scrapy.Request(url, callback=self.parse_jobs, dont_filter=True)
def parse_jobs(self, response):
...
yield item
建議研究一下scrapy
官網(wǎng)內(nèi)容:http://scrapy-chs.readthedocs...
已解決
def parse(self, response):
li_list = response.css("div.list_cont.Left_list_cont.Left_list_cont1 > div.tab_tj > div > div > ul > li")
url_list = []
for li in li_list:
item = CardItem()
href = li.css("a::attr(href)").extract_first()
item['href'] = href
item['title'] = li.css("a::attr(title)").extract_first()
url_list.append(href)
yield item
for i in url_list:
print("->>> %s" % i)
yield scrapy.Request(url=i, callback=self.detail_parse, headers=self.headers)沒有css,無法確定你的問題。
應(yīng)該是這個div的外層結(jié)點有width限制了。
我完全復(fù)制粘貼了你的代碼。。并沒有發(fā)生你所截圖的情況。
另外 你這注釋的方式。。在template里不是應(yīng)該遵循h(huán)tml的注釋方式么。你看我這圖里你的注釋都被當成text輸出了。所以你這構(gòu)建環(huán)境具體怎么樣的和vue版本、package乃至開發(fā)工具都最好貼出來給大家參詳 避免玄學(xué)問題。。
大概看懂了,你的意思是如果去匹配出來,只有少于或等于兩個字符不能匹配上,就算找到了是吧,我把條件列一下
import re
if re.match(r'^.{0,6}首長四方財務(wù)有限公司$', '北京首長四方財務(wù)有限公司') or re.match(r'^首長四方財務(wù)有限公司.{0,6}$', '北京首長四方財務(wù)有限公司')
......
用.{0,6}判定首尾最多6個字符不匹配上,其中1個漢字占3個字符。
希望能幫助到你。
js所在頁和你接口地址,不是跨域關(guān)系吧?如果是跨域的話,jq是會發(fā)起兩次請求的,一次是 OPTION ,一次是 POST 。
題外話,你redis用的是string,也不是不行,就是到時候會有多少個key你自己管理起來會累死,而且也不好做關(guān)鍵詞排名,推薦哈希集或者有序集合
kafka里面有單播和廣播的區(qū)別,對一條消息來說,同一個消費組內(nèi)的消費者有競態(tài)關(guān)系,只有一個消費者能消費,這個是單播;同樣,對一條消息,不同消費組的消費者都可以同時消費,這是多播。假如你想讓兩個消費者都能同時消費到消息,你可以將這兩個消費者放在不同的消費組,這個需要消費端的groupId屬性來設(shè)置。
問題解決了。直接將core-site.xml文件拷貝到classpath下,或者添加如下配置即可:
conf.set("hadoop.tmp.dir", "/home/parallels/app/hadoop-2.4.1/data/");內(nèi)存問題可以使用valgrind定位。
“double free”或者“Segmentation fault” 要給出具體異常信息,光給個代碼片段沒什么用
Django models支持abstract=True屬性, 設(shè)置這個屬性后, 這個models不會在創(chuàng)建表, 專門用來繼承, 具體的可以看官方文檔 Models Abstract base classes部分.
Abstract base classes
Abstract base classes are useful when you want to put some common information into a number of other models. You write your base class and put abstract=True in the Meta class. This model will then not be used to create any database table. Instead, when it is used as a base class for other models, its fields will be added to those of the child class. It is an error to have fields in the abstract base class with the same name as those in the child (and Django will raise an exception).
from django.db import models
class CommonInfo(models.Model):
name = models.CharField(max_length=100)
age = models.PositiveIntegerField()
class Meta:
abstract = True
class Student(CommonInfo):
home_group = models.CharField(max_length=5)
The Student model will have three fields: name, age and home_group. The CommonInfo model cannot be used as a normal Django model, since it is an abstract base class. It does not generate a database table or have a manager, and cannot be instantiated or saved directly.
實現(xiàn)key-value咯,參見https://www.zhihu.com/question/30527705。
當然時間多的話你可以對比各種查找樹實現(xiàn)key-value存儲結(jié)構(gòu)的存儲和查詢效率,搞個benchmark,然后就可以寫一篇博客。
自問自答,結(jié)束
不一定越多越好,建議你看看這個。這個回答比較專業(yè),提到了層數(shù)和節(jié)點數(shù)量的關(guān)系。
神經(jīng)網(wǎng)絡(luò)如何選擇隱藏層的數(shù)量
不知道ab.exe測試時什么原理,你自己寫一個多線程調(diào)用下就知道了會產(chǎn)生負數(shù)值的。
//php不會,用java寫了個test。
import redis.clients.jedis.Jedis;
public class Test {
public static void main(String[] args) throws Exception {
Jedis jedis = getJedis();
jedis.set("nums", 50+"");
close(jedis);
for(int i = 0;i < 1000;i++){ //啟動1000個線程
new Thread(new MyTask()).start();
}
}
public static Jedis getJedis(){
Jedis j = new Jedis("xxxxx", 6379);
j.auth("xxxx");
return j;
}
public static void close(Jedis jedis){
if(null == jedis){
return;
}
jedis.close();
}
}
class MyTask implements Runnable{
@Override
public void run() {
Jedis j = Test.getJedis();
String numStr = j.get("nums");
Integer nums = Integer.valueOf(numStr);
if(nums > 1){
j.decr("nums");
}else{
System.out.println(nums);
}
Test.close(j);
}
}
輸出結(jié)果出現(xiàn)負值。
google 了一晚上,終于找到了比較滿意的方法,下面是整個的 RedisCacheConfig 文件
@Configuration
public class RedisCacheConfig {
@Bean
public KeyGenerator simpleKeyGenerator() {
return (o, method, objects) -> {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(o.getClass().getSimpleName());
stringBuilder.append(".");
stringBuilder.append(method.getName());
stringBuilder.append("[");
for (Object obj : objects) {
stringBuilder.append(obj.toString());
}
stringBuilder.append("]");
return stringBuilder.toString();
};
}
@Bean
public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
return new RedisCacheManager(
RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory),
this.getRedisCacheConfigurationWithTtl(600), // 默認策略,未配置的 key 會使用這個
this.getRedisCacheConfigurationMap() // 指定 key 策略
);
}
private Map<String, RedisCacheConfiguration> getRedisCacheConfigurationMap() {
Map<String, RedisCacheConfiguration> redisCacheConfigurationMap = new HashMap<>();
redisCacheConfigurationMap.put("UserInfoList", this.getRedisCacheConfigurationWithTtl(3000));
redisCacheConfigurationMap.put("UserInfoListAnother", this.getRedisCacheConfigurationWithTtl(18000));
return redisCacheConfigurationMap;
}
private RedisCacheConfiguration getRedisCacheConfigurationWithTtl(Integer seconds) {
Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<>(Object.class);
ObjectMapper om = new ObjectMapper();
om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
jackson2JsonRedisSerializer.setObjectMapper(om);
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig();
redisCacheConfiguration = redisCacheConfiguration.serializeValuesWith(
RedisSerializationContext
.SerializationPair
.fromSerializer(jackson2JsonRedisSerializer)
).entryTtl(Duration.ofSeconds(seconds));
return redisCacheConfiguration;
}
}
要指定 key 的過期時間,只要在getRedisCacheConfigurationMap方法中添加就可以。
然后只需要 @Cacheable 就可以把數(shù)據(jù)存入 redis
@Cacheable(value = "UserInfoList", keyGenerator = "simpleKeyGenerator") // 3000秒
@Cacheable(value = "UserInfoListAnother", keyGenerator = "simpleKeyGenerator") // 18000秒
@Cacheable(value = "DefaultKeyTest", keyGenerator = "simpleKeyGenerator") // 600秒,未指定的key,使用默認策略
一般都是這樣實現(xiàn) 你可以參考下
還是沒搞定。感覺要放棄這個模型
終端輸入2次 # 回車
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。