在 re.compile 中使用变量
for issn in inputList:
link = journalresults.find('a', attrs={'href' : re.compile(issn + '$')})
我试图将变量“issn”与 re.compile 一起使用,并在其后附加“$”,但在搜索解决方案时尝试了无数组合,但均未成功。
显然我错过了一些简单的东西。我只是想在 href 属性中找到“issn”。它出现在末尾,这就是为什么我想在“issn”变量后面附加 $ 的原因。
编辑:使用注释尝试“print >>sys.stderr, repr(issn)”,我看到 issn 后面有一个换行符,我需要删除它。感谢新手的帮助。
for issn in inputList:
link = journalresults.find('a', attrs={'href' : re.compile(issn + '
I am trying to use the variable 'issn' with re.compile and append '$' after it but have tried umpteen combinations while searching for a resolution that all have come up unsucessful.
Obviously I am missing something simple. I am just looking to find 'issn' within the href attribute. It appears at the end so that is why I want to append $ after the 'issn' variable.
Edit: using the comment to try 'print >>sys.stderr, repr(issn)', I see there is a newline after the issn that I needed to strip. Thank you for the newbie help.
)})
I am trying to use the variable 'issn' with re.compile and append '$' after it but have tried umpteen combinations while searching for a resolution that all have come up unsucessful.
Obviously I am missing something simple. I am just looking to find 'issn' within the href attribute. It appears at the end so that is why I want to append $ after the 'issn' variable.
Edit: using the comment to try 'print >>sys.stderr, repr(issn)', I see there is a newline after the issn that I needed to strip. Thank you for the newbie help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你检查过变量 issn 是什么类型吗?使用
print >>sys.stderr, repr(issn)
并检查您得到的结果。另外,打印什么错误消息?您是否调试过您的程序,例如在顶部使用 import pdb 并在编译语句之前使用 pdb.set_trace() ?Did you check what type the variable
issn
is? Useprint >>sys.stderr, repr(issn)
and check what you get. Additionally, what error message is printed? Did you debug your program, for example by using import pdb at the top and using pdb.set_trace() right before the compile statement?