我试图写一个简单的脚本与美丽的汤,可以废料只是两个信息,并生成一个SQL文件请从一个网站。你知道吗
import mechanize
import urlparse
from bs4 import BeautifulSoup
op = mechanize.Browser()
op.open("https://www.mentalhelp.net/symptoms/")
for link in op.links():
print link.text
print urlparse.urljoin(link.base_url, link.url)
get = BeautifulSoup(urllib2.urlopen("https://www.mentalhelp.net/symptoms/").read()).findAll('p')
print get
print "\n"
错误:
C:\Python27>python symtoms.py File "symtoms.py", line 8 print link.text ^ IndentationError: expected an indented block
我只需要一个脚本,它将取消这些项目和简短的描述,并生成一个SQL文件,其中将只有两个字段“name”&;“sug”“name”是那些项目,“sug”是那些描述。你知道吗
缩进在Python中很重要,它用于确定块,如for循环、if块、while循环或函数等
在您给出的代码中,for循环后面的语句在for循环中没有正确缩进,for循环希望其主体中至少有一条语句,我认为您希望for循环下面的行在for循环中,因此您应该在for循环中缩进它们。你知道吗
代码-
虽然我不确定这是否会得到你想要的,它会修复你目前的错误。你知道吗
对于只获取
classic symptoms
及其描述的新需求,可以使用-相关问题 更多 >
编程相关推荐