मैं अजगर के लिए बहुत नया हूं। बहुत नया। मैं एक ट्यूटोरियलनाम त्रुटि: नाम 'पुनः' परिभाषित नहीं किया गया है
#!/usr/bin/python
import re
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
webpage = urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read
patFinderTitle = re.compile('<title>(.*)</title>')
patFinderLink = re.compile('<link rel.*href="(.*)"/>')
findPatTitle = re.findall(patFinderTitle,webpage)
findPatLink = re.findall(patFinderLink,webpage)
listIterator = []
listIterator[:] = range(2,16)
for i in listIterator:
print findPatTitle[i]
print findPatLink[i]
print "\n"
से निम्नलिखित की नकल की मैं त्रुटि मिलती है:
Traceback (most recent call last):
File "test.py", line 8, in <module>
patFinderTitle = re.compile('<title>(.*)</title>')
NameError: name 're' is not defined
क्या मैं गलत कर रहा हूँ?
संपादित करें: मैं import re
जोड़ा है, लेकिन अब निम्नलिखित मिलती है:
File "/scripts/_prod/test.py", line 13, in <module>
findPatTitle = re.findall(patFinderTitle,webpage)
File "/usr/lib64/python2.6/re.py", line 177, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
के बाद आपने इसे किस ट्यूटोरियल से कॉपी किया था? यह त्रुटियों से भरा हुआ है। – Johnsyweb
http://www.youtube.com/watch?v=Ap_DlSrT-iE&feature=related –
फिर आपको अपने कोड की तुलना यहां कोड के साथ करना चाहिए: http://www.newthinktank.com/2010/11/python-2 -7-ट्यूटोरियल-pt-13-वेबसाइट-स्क्रैपिंग /। थोड़ा साफ-सुथरा होने के बाद मैंने पाया कि यह काम करता है। – Johnsyweb