我目前运行一个进度条作为web刮刀的一部分,但它显得既计数URL的控制台,而不是进度条
(A)不准确 (B)缓慢的过程是什么。
with click.progressbar(range(1000000)) as bar:
for i in bar:
pass
是否有文章/培训,我将能够阅读以更好地了解打印进度到控制台?
我有效地希望程序扫描列表中的网址,然后打印的进展,因为它遍历列表,沿着
扫描URL 1的30
扫描线的东西的30扫描URL 3 30的
如果可能的话,保持对同一行,但不是必需的。
代码如下 - 如果有人能与任何培训或阅读帮助,我们将不胜感激。
import requests
import csv
from lxml import html
URL_LIST = [
"https://www.realestate.com.au/property/1-1-goldsmith-st-elwood-vic-3184",
"https://www.realestate.com.au/property/1-10-albion-rd-glen-iris-vic-3146",
"https://www.realestate.com.au/property/1-109-sydney-rd-manly-nsw-2095",
"https://www.realestate.com.au/property/1-1110-glen-huntly-rd-glen-huntly-vic-3163",]
with open('test.csv', 'wb') as csv_file:
writer = csv.writer(csv_file)
for index, url in enumerate(URL_LIST):
page = requests.get(url)
print 'scanning url....'
if text2search in page.text:
tree = html.fromstring(page.content)
(title,) = (x.text_content() for x in tree.xpath('//title'))
(price,) = (x.text_content() for x in tree.xpath('//div[@class="property-value__price"]'))
(sold,) = (x.text_content().strip() for x in tree.xpath('//p[@class="property-value__agent"]'))
writer.writerow([title, price, sold])
这正是我正在寻找的,只需要缩短一点,并删除URL的打印,但这足以让我自己成长。 – James2086
刚刚删除最后一节 - 所以现在读取 '扫描URL#'+ str(索引+ 1)+'的'+ str(len(URL_LIST)) 输出为 正在扫描URL#1 of 7 – James2086
没有找一个简单的答案,因为我喜欢尝试为自己工作 - 但是有没有一种方法,以便在同一行上打印而不是回车? – James2086