【发布时间】:2012-06-25 04:21:30
【问题描述】:
我正在尝试打印 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]
【问题讨论】:
-
跟着我重复:不要使用正则表达式解析 Html,不要使用正则表达式解析 Html,不要使用.. 不,真的,不要那样做 - 有它的库.
-
如果您打算重新发布此信息,您可能需要获得您从中抓取该信息的网站的许可。在您为这个项目投入大量精力之前,可能值得检查一下!
-
使用pyquery
标签: python web-scraping screen-scraping