代码:
import url_get
from bs4 import BeautifulSoup
import re
def news_select(url,fold_name,*selectors):
html = url_get.get_html(url) #获取html
soup = BeautifulSoup(html,'html.parser') #定义一个Soup对象
#newses = soup.select('ul.pic_lists > li')
for selector in selectors:
try:
newes = soup.select(selector) # 一定注意selector的正确性
href = soup.find('a',href=re.compile(r"[0-9a-zA-Z/.]{1,}")) #匹配href
print(href['href'])
print(item.get_text().strip()) #去掉首位空格
报错
SyntaxError: unexpected EOF while parsing
原因
写了try,忘写except…