我想从这个网站http://tweakers.net获得智能手机的价格。这是一个荷兰网站。问题是价格不是从网站上收集的。
文本文件“TweakersTelefoons.txt”包含 3 个条目:
三星-galaxy-s6-32gb-zwart
lg-nexus-5x-32gb-zwart
华为-nexus-6p-32gb-zwart
我正在使用 python 2.7,这是我使用的代码:
import urllib
import re
symbolfile = open("TweakersTelefoons.txt")
symbolslist = symbolfile.read()
symbolslist = symbolslist.split("\n")
for symbol in symbolslist:
url = "http://tweakers.net/pricewatch/[^.]*/" +symbol+ ".html"
## http://tweakers.net/pricewatch/423541/samsung-galaxy-s6-32gb-zwart.html is the original html
htmlfile = urllib.urlopen(url)
htmltext = htmlfile.read()
regex = '<span itemprop="lowPrice">(.+?)</span>'
## <span itemprop="lowPrice">€ 471,95</span> is what the original code looks like
pattern = re.compile(regex)
price = re.findall(pattern, htmltext)
print "the price of", symbol, "is ", price
输出:
samsung-galaxy-s6-32gb-zwart 的价格是 []
lg-nexus-5x-32gb-zwart 的价格是 []
huawei-nexus-6p-32gb-zwart的价格是[]
价格未显示我尝试使用 [^.] 摆脱欧元符号,但没有奏效。
此外,在欧洲,我们可能使用“,”而不是“。”。作为小数的分隔符。请帮忙。
先感谢您。