通過下程式設計客棧面這段**可以一目了然的知道scrapy的抓取頁面結構,呼叫也非常簡單
#!/usr/bin/env python
import fileinput, re
from collections import defaultdict
def print_urls(allurls, referer, indent=0):
urls = allurls[referer]
for url in urls:
print ' '*indent + referer
if url in allurls:
print_urls(allurlsquqqiyc, url, indent+2)
def main():
log_re quqqiyc= re.compile(r' \(referer: (.*?)\)')
allurls = defaultdict(list)
for l in fileinput.input():
m = log_re.search(l)
if m:
url, ref =
allurls[ref] += [url]
print_urls(allurls, 'none')
main()
本文標題: python列印scrapy蜘蛛抓取樹結構的方法
本文位址:
python語言列印菱形 Python列印菱形
示例1 usr bin python coding utf 8 根據輸入列印 rows int raw input please input number 列印菱形上半部分 for i in range rows for j in range rows i print j 1 for k in ra...
python語言列印菱形 Python列印菱形
示例1 usr bin python coding utf 8 根據輸入列印 rows int raw input please input number 列印菱形上半部分 for i in range rows for j in range rows i print j 1 for k in ra...
python 列印對齊 python 列印對齊
一 數值型別 int float d f是佔位符 a 3.1415926 print d a d只能輸出整數,int類 print f a f輸出浮點數 3.141593 print 2f a 按照要求輸出小數字數 3.14 print 9f a 如果要求的小數字數過多,後面就用0補全 3.1415...