Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用Python和BeautifulSoup error TypeError进行web抓取:只能将str(而不是“NoneType”)连接到str_Python 3.x_Beautifulsoup - Fatal编程技术网

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)

非常感谢非常感谢