Python 3.x 使用Python和BeautifulSoup error TypeError进行web抓取:只能将str(而不是“NoneType”)连接到str
`#我的最后三行代码应该如何更正?``为Python 3.x 使用Python和BeautifulSoup error TypeError进行web抓取:只能将str(而不是“NoneType”)连接到str,python-3.x,beautifulsoup,Python 3.x,Beautifulsoup,`#我的最后三行代码应该如何更正?``为link.get('href')函数提供默认值:link.get('href','')。默认值为None,因此如果链接没有“href”属性,则会出现错误 anchors = soup.find_all('a')`all_links = set()`for link in anchors: if (link.get('href') != '#'):`linkText = "https://www.newegg.com/" + `link.
link.get('href')
函数提供默认值:link.get('href','')
。默认值为None
,因此如果链接没有“href”属性,则会出现错误
anchors = soup.find_all('a')`all_links = set()`for link in anchors:
if (link.get('href') != '#'):`linkText = "https://www.newegg.com/" + `link.get('href')``all_links.add(link)`print(linkText)
为
link.get('href')
函数提供默认值:link.get('href','')
。默认值为None
,因此如果链接没有“href”属性,则会出现错误
anchors = soup.find_all('a')`all_links = set()`for link in anchors:
if (link.get('href') != '#'):`linkText = "https://www.newegg.com/" + `link.get('href')``all_links.add(link)`print(linkText)
非常感谢非常感谢