for imgsrc in Soup.findAll('img', {'class': 'sizedProdImage'}):
if imgsrc:
imgsrc = imgsrc
else:
imgsrc = "ERROR"
patImgSrc = re.compile('src="(.*)".*/>')
findPatImgSrc = re.findall(patImgSrc, imgsrc)
print findPatImgSrc
'''
<img height="72" name="proimg" id="image" class="sizedProdImage" src="http://imagelocation" />
Run Code Online (Sandbox Code Playgroud)
这就是我想从中提取的内容,我得到了:
findimgsrcPat = re.findall(imgsrcPat, imgsrc)
File "C:\Python27\lib\re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
Run Code Online (Sandbox Code Playgroud)
"""
from Tkinter import *
import webbrowser
root = Tk()
frame = Frame(root)
frame.pack()
url = 'http://www.sampleurl.com'
def OpenUrl(url):
webbrowser.open_new(url)
button = Button(frame, text="CLICK", command=OpenUrl(url))
button.pack()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)
我的目标是在单击 GUI 小部件中的按钮时打开一个 URL。但是,我不确定如何执行此操作。
当我在不单击任何内容的情况下运行脚本时,Python 会打开两个新窗口。此外,当我单击按钮时没有任何反应。
将输出列表和变量很好地输入HTML模板的最佳方法是什么?
list = ['a', 'b', 'c']
template = '''<html>
<title>Attributes</title>
- a
- b
- c
</html>'''
Run Code Online (Sandbox Code Playgroud)
有更简单的方法吗?
data = ['cat', 'dog', 'None', 'Turtle', 'None']
new_data = []
for item in data:
if item == 'None':
new_data.append(data.index(item))
print new_data
>> [2,2]
Run Code Online (Sandbox Code Playgroud)
我该如何获得这个商店的新数据[2,4]呢?这就是我要的.谢谢!
我正在使用imaplib在我的python命令窗口中读取gmail消息.唯一的问题是,如果电子邮件附带换行符和返回车厢.此外,文本似乎没有正确格式化.而不是金额:36.49美元,它返回= 2436.49.我怎样才能清理这个文本?谢谢!
电子邮件内容示例
r\nItem name: Scanner\r\nItem=23: 130585100869\r\nPurchase Date: Oct 7, 2011\r\nUnit Price: =2436.49 USD\r\nQty: 1\r\nAmount: =2436.49USD\r\nSubtotal: =2436.49 USD\r\nShipping and handling: =240.00 USD\r\nInsurance - not offered
Run Code Online (Sandbox Code Playgroud)
码:
import imaplib
import libgmail
import re
import email
from BeautifulSoup import BeautifulSoup
USER = 'email@gmail.com'
PASSWORD = 'password'
#connecting to the gmail imap server
imap_server = imaplib.IMAP4_SSL('imap.gmail.com', 993)
imap_server.login(USER, PASSWORD)
imap_server.select('Inbox')
typ, response = imap_server.search(None, '(SUBJECT "payment received")')
Data = []
for i in response[0].split():
results, data = imap_server.fetch(i, "(RFC822)")
Data.append(data)
break
for i …Run Code Online (Sandbox Code Playgroud) 我试图将列表中的项连接到字符串上.
list = ['a', 'b', 'c', 'd']
string = ''
for i in list:
string.join(str(i))
Run Code Online (Sandbox Code Playgroud) 特定
listEx = ['cat', 'dog', 'cat', 'turtle', 'apple', 'bird', 'bird']
for i in listEx:
if listEx.count(i) > 1:
print "this item appears more than once", i
else:
print "this item appears only once", i
Run Code Online (Sandbox Code Playgroud)
我希望它打印出猫和鸟出现不止一次(或只是生产['cat', 'bird']).我怎样才能做到这一点?
#<link rel='canonical' href='http://www.samplewebsite.com/image/5434553/' />
#I am trying to grab the text in href
image = str(Soup)
image_re = re.compile('\<link rel=\'cononical\' href=')
image_pat = re.findall(image_re, image)
print image_pa
#>> []
#Thanks!
Run Code Online (Sandbox Code Playgroud)