我用python写了一个刮刀。我有一组字符串,我想在页面上搜索,并从结果中,我想删除这些结果,其中包含的字从另一组字符串我有。你知道吗
这是密码-
def find_jobs(self, company, soup):
allowed = re.compile(r"Developer|Engineer|Designer|Admin|Manager|Writer|Executive|Lead|Analyst|Editor|"
r"Associate|Architect|Recruiter|Specialist|Scientist|Support|Expert|SSE|Head|"
r"Producer|Evangelist|Ninja", re.IGNORECASE)
not_allowed = re.compile(r"^responsibilities$|^description$|^requirements$|^experience$|^empowering$|^engineering$|^"
r"find$|^skills$|^recruiterbox$|^google$|^communicating$|^associated$|^internship$|^you$|^"
r"proficient$|^leadsquared$|^referral$|^should$|^must$|^become$|^global$|^degree$|^good$|^"
r"capabilities$|^leadership$|^services$|^expertise$|^architecture$|^hire$|^follow$|^jobs$|^"
r"procedures$|^conduct$|^perk$|^missed$|^generation$|^search$|^tools$|^worldwide$|^contact$|^"
r"question$|^intern$|^classes$|^trust$|^ability$|^businesses$|^join$|^industry$|^response$|^"
r"using$|^work$|^based$|^grow$|^provide$|^understand$|^header$|^headline$|^masthead$|^office$", re.IGNORECASE)
profile_list = set()
k = soup.body.findAll(text=allowed)
for i in k:
if len(i) < 60 and not_allowed.search(i) is None:
profile_list.add(i.strip().upper())
self.update_jobs(company, profile_list)
所以我在这里面临一个问题。使用not_allowed
中的锚定标记,像//HEADLINE-BG
和ABILITY TO LEAD & MENTOR A TEAM
这样的字符串可以通过,尽管我在not_allowed
中有字符串headline
和ability
。如果我删除了锚定标记,但是由于not_allowed
中的字符串ability
,像SCALABILITY ENGINEER
这样的字符串没有被保存,那么这些都会被删除。所以作为regex的新手,我不知道如何才能让它工作。之前我用过这个-
def find_jobs(self, company, soup):
allowed = re.compile(r"Developer|Designer|Engineer|Admin|Manager|Writer|Executive|Lead|Analyst|Editor|"
r"Associate|Architect|Recruiter|Specialist|Scientist|Support|Expert|SSE|Head"
r"Producer|Evangelist|Ninja", re.IGNORECASE)
not_allowed = ['responsibilities', 'description', 'requirements', 'experience', 'empowering', 'engineering',
'find', 'skills', 'recruiterbox', 'google', 'communicating', 'associated', 'internship',
'proficient', 'leadsquared', 'referral', 'should', 'must', 'become', 'global', 'degree', 'good',
'capabilities', 'leadership', 'services', 'expertise', 'architecture', 'hire', 'follow',
'procedures', 'conduct', 'perk', 'missed', 'generation', 'search', 'tools', 'worldwide', 'contact',
'question', 'intern', 'classes', 'trust', 'ability', 'businesses', 'join', 'industry', 'response', 'you', 'using', 'work', 'based', 'grow', 'provide']
profile_list = set()
k = soup.body.findAll(text=allowed)
for i in k:
if len(i) < 60 and not any(x in i.lower() for x in not_allowed):
profile_list.add(i.strip().upper())
self.update_jobs(company, profile_list)
但是如果子字符串存在于not_allowed
中,则也省略了一个字符串。请任何人帮帮忙。你知道吗
看起来你的正则表达式写错了。你的notallowed regex实际上是在寻找那些单词是行中唯一的项目。你知道吗
re.compile(r'^something_i_dont_like$')
将匹配某个我不喜欢的项,如果它是行中唯一的项如果你想省略一些东西,你需要做一个消极的展望
re.compile(r'^((?!something_i_dont_like).)*$')
正则表达式
意思是“该行仅由“能力”一词组成”。如果需要子字符串,只需更改为
如果你想省略“能力”这个词,而不是“残疾”,那么使用
相关问题 更多 >
编程相关推荐