모든 특정 웹 페이지를 가져 와서 배열로 전달하는 데 FINDALL을 사용해야합니다. 따옴표없이 링크 만 사용합니다. 배열이 아닌 경우 전달할 수있는 변수가 있습니다. 내가 한 번배열에 대한 파이썬 findall 변환
#!/usr/bin/env python
import re,urllib,urllib2
Url = "http://www.ihiphopmusic.com/music"
print Url
print 'test .............'
req = urllib2.Request(Url)
print "1"
response = urllib2.urlopen(req)
print "2"
#reads the webpage
the_webpage = response.read()
#grabs the title
the_list = re.findall(r'number-link" href="(.*?)#comments">0</a>',the_webpage)
print "3"
the_list = the_list.split(',')
arrlist = array('c',the_list)
print arrlist
결과
http://www.ihiphopmusic.com/music
test .............
1
2
3
Traceback (most recent call last):
File "grub.py", line 17, in <module>
the_list = the_list.split(',')
AttributeError: 'list' object has no attribute 'split'
당신은 Zalgo를 이렇게 깨울 것입니다 ... http://stackoverflow.com/a/1732454/53936 – JosefAssad
html을 정규식으로 구문 분석하지 마십시오. 매우 쉽게 원하는 것을 성취 할 수있는 lxml 또는 BeautifulSoup 라이브러리를 사용하십시오. – Lanaru