-2

NBA ドラフトの最初の 30 ピックを印刷しようとしています。私は次のページを使用しています: http://nbadraft.net/2012mock_draft情報。実行すると、次のように表示されます。

invalid syntax: python1.py, line 8, pos 28
File "/Users/seanyeh/Downloads/python1.py", line 8, in ?
  patFinderLink = re.compile(‘<link rel.*href=”(.*)” />’)

これは私のコードです:

import urllib2
from BeautifulSoup import BeautifulSoup
# or if your're using BeautifulSoup4:
# from bs4 import BeautifulSoup

soup = BeautifulSoup(urllib2.urlopen('http://nbadraft.net/2012mock_draft').read())

patFinderLink = re.compile(‘<link rel.*href=”(.*)” />’)

findPatLink = re.findall(patFinderLink,webpage)

listIterator = []
listIterator[:] = range(1,30)

for i in listIterator:
    print findPatLink[i]
4

1 に答える 1

3

You have some funny characters on this line (perhaps this is due to cut-and-paste?)

 ‘<link rel.*href=”(.*)” />’)

also, I believe you are missing

 import re

in your code. I also get an error that webpage isn't defined.

Since you are using BeautifulSoup, why not use it to extract the elements you are interested in? The whole idea with BeautifulSoup is to avoid "manual" parsing using string ops or regular expressions.

于 2012-06-22T20:20:28.943 に答える