//python SyntaxError: invalid syntax 语法错误,但我看不出来是哪里,求指导 10
python35里beautifulsoup4.4.1....新手小白,入门第三天,简直要哭。。。居然已经折腾到一点了还是没有办法运行,求大神指导代码是这样的import...
python35里 beautifulsoup4.4.1....新手小白,入门第三天,简直要哭。。。居然已经折腾到一点了还是没有办法运行,求大神指导
代码是这样的
import requests, urllib.request
from bs4 import BeautifulSoup
url = 'http://g.jandan.net/n/hanzi?&page=5'
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0'}
source_code = requests.get(url, headers=header)
plain_text = source_code.text
Soup = BeautifulSoup(plain_text)
download_links = []
folder_path = 'C:\\Users\wenyan\Desktop\12.7'
for pic_tag in Soup.find_all('img'):
pic_link = pic_tag.get('src')
download_links.append(pic_link)
for item in download_links:
urllib.request.urlretrieve(item, folder_path+item[-10:])
print('Done')
错误是这样的
C:\Users\wenyan\AppData\Local\Programs\Python\Python35\python.exe D:/Users/wenyan/PycharmProjects/untitled/12.7.py
Traceback (most recent call last):
File "D:/Users/wenyan/PycharmProjects/untitled/12.7.py", line 2, in <module>
from bs4 import BeautifulSoup
File "C:\Users\wenyan\AppData\Local\Programs\Python\Python35\lib\bs4\__init__.py", line 355
print soup.prettify()
^
SyntaxError: invalid syntax 展开
代码是这样的
import requests, urllib.request
from bs4 import BeautifulSoup
url = 'http://g.jandan.net/n/hanzi?&page=5'
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0'}
source_code = requests.get(url, headers=header)
plain_text = source_code.text
Soup = BeautifulSoup(plain_text)
download_links = []
folder_path = 'C:\\Users\wenyan\Desktop\12.7'
for pic_tag in Soup.find_all('img'):
pic_link = pic_tag.get('src')
download_links.append(pic_link)
for item in download_links:
urllib.request.urlretrieve(item, folder_path+item[-10:])
print('Done')
错误是这样的
C:\Users\wenyan\AppData\Local\Programs\Python\Python35\python.exe D:/Users/wenyan/PycharmProjects/untitled/12.7.py
Traceback (most recent call last):
File "D:/Users/wenyan/PycharmProjects/untitled/12.7.py", line 2, in <module>
from bs4 import BeautifulSoup
File "C:\Users\wenyan\AppData\Local\Programs\Python\Python35\lib\bs4\__init__.py", line 355
print soup.prettify()
^
SyntaxError: invalid syntax 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询