本文整理汇总了Python中webpage.WebPage.getContent方法的典型用法代码示例。如果您正苦于以下问题:Python WebPage.getContent方法的具体用法?Python WebPage.getContent怎么用?Python WebPage.getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webpage.WebPage
的用法示例。
在下文中一共展示了WebPage.getContent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: OnMouseDown
# 需要导入模块: from webpage import WebPage [as 别名]
# 或者: from webpage.WebPage import getContent [as 别名]
def OnMouseDown(event, arg, login, password, instr, flag, link, canvas):
words = []
for i in xrange(len(arg)):
if (arg[i].get() != ""):
words += [arg[i].get()]
if flag.get() == 1:
# only to set the link
page = WebPage(words)
link.set(page.link)
# get data locally
globalFile = open('data.csv', 'r')
globalC = globalFile.read()
globalCon = ""
for line in globalC:
globalCon += line
regex = '[0-9]+-.*?-.*?'
for i in xrange(len(words)):
regex += ',[0-9]+'
globalInfo = re.findall(regex,globalCon)
regex = ""
for i in xrange(len(words)):
regex += ',[0-9]+'
globalData = []
for i in xrange(len(globalInfo)):
temp = re.findall(regex,globalInfo[i])
num = re.findall(r'\d+',temp[0])
globalData += num
# read individual
allwords = []
for i in xrange(len(words)):
string = words[i] + ".csv"
fle = open(string, 'r')
file1 = fle.read()
con = ""
for line in file1:
con += line
info = re.findall(r'[0-9]+-.*?-.*?,[0-9]+',con)
data = []
for j in xrange(len(info)):
temp = re.findall(',[0-9]+',info[j])
num = re.findall(r'\d+',temp[0])
data += num
allwords.append(data)
# output
output = open('Java/LetTheDataSpeak/data.txt','w')
for i in xrange(len(allwords[0])):
for j in xrange(len(allwords)):
output.write(allwords[j][i] + " " + globalData[i*len(words)+j] + " ")
output.write("\n")
else:
# get data from website
page = WebPage(words)
link.set(page.link)
page.getContent(login,password)
# get global data
globalFile = open('data.csv', 'r')
globalC = globalFile.read()
globalCon = ""
for line in globalC:
globalCon += line
regex = '[0-9]+-.*?-.*?'
for i in xrange(len(words)):
regex += ',[0-9]+'
globalInfo = re.findall(regex,globalCon)
regex = ""
for i in xrange(len(words)):
regex += ',[0-9]+'
globalData = []
for i in xrange(len(globalInfo)):
temp = re.findall(regex,globalInfo[i])
num = re.findall(r'\d+',temp[0])
globalData += num
for i in xrange(len(words)):
page = WebPage([words[i]])
link.set(page.link)
page.getContent(login,password)
# rename
for i in xrange(len(words)):
bashCommand = "rename "
bashCommand += "data(" + str(i+1) + ").csv " + words[i] + ".csv"
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
# read individual
allwords = []
for i in xrange(len(words)):
#.........这里部分代码省略.........