-5 python
这是我试图运行的代码:
url = "https://remoteok.io/"
response = requests.get(url,timeout=5)
content= BeautifulSoup(response.content, "lxml") jobArr = []
for post in content.findAll('table', attrs={"id":"jobboard"}):
postObject={
"company": post.find('td', attrs={"class": "company position company_and_position"}).text.encode('utf-8'),
"job name": post.find('h3', attrs={"itemprop": "name"}).text.encode(utf-8),
"title": post.find('h2', attrs={"itemprop": "title"}).text.encode(utf-8),
"tags": post.find('td', attrs={"class": "tags"}).text.encode(utf-8),
"time": post.find('td', attrs={"class": "time"}).text.encode(utf-8),
"description": post.find('div', attrs={"class": "description"}).text.encode(utf-8),
"markdown": post.find("div", attrs={"class": "markdown"}).text.encode(utf-8)
}
print postObject
Run Code Online (Sandbox Code Playgroud)
但每次我尝试运行该文件时,都会出现以下错误:
File "/home/user/Desktop/pythonscrap/webscraper.py", line 6
content= BeautifulSoup(response.content, "lxml") jobArr = [];
^
SyntaxError: invalid syntax
[Finished in 0.044s]
Run Code Online (Sandbox Code Playgroud)
我不明白我错过了什么 - 请帮忙!
这行:
content= BeautifulSoup(response.content, "lxml") jobArr = []
Run Code Online (Sandbox Code Playgroud)
没有任何意义。它有两个语句,因此它们需要位于两个单独的行上:
content= BeautifulSoup(response.content, "lxml")
jobArr = []
Run Code Online (Sandbox Code Playgroud)
您还可以使用分号来分隔这两个语句,但从主观上来说,这是一种极其糟糕的风格,并且通常会令人皱眉。