|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码如下:
- import urllib.request
- import re
- from bs4 import BeautifulSoup
- def main():
- url = "http://baike.baidu.com/view/284853.htm"
- response = urllib.request.urlopen(url)
- html = response.read()
- soup = BeautifulSoup(html,"html.parser")
- for each in soup.find_all(href = re.compile("view")):
- print(each.text,"->",''.join(["http://baike.baidu.com",\ each["href"]]))
-
- if __name__ == "__main__":
- main()
复制代码
报错信息:
- File "/home/hongludianxue/Documents/Python file/爬虫.py", line 13
- print(each.text,"->",''.join(["http://baike.baidu.com",\ each["href"]]))
- ^
- SyntaxError: unexpected character after line continuation character
复制代码
实在找不出错在了哪里,请师傅们帮忙看一下,十分感谢。
附书的第172页代码段:
- import urllib.request
- import re
- from bs4 import BeautifulSoup
- def main():
- url = "http://baike.baidu.com/view/284853.htm"
- response = urllib.request.urlopen(url)
- html = response.read()
- soup = BeautifulSoup(html,"html.parser")
- for each in soup.find_all(href = re.compile("view")):
- print(each.text,"->",''.join(["http://baike.baidu.com",each["href"]]))
-
- if __name__ == "__main__":
- main()
复制代码
|
|