我對編碼很陌生,最近我開始研究網(wǎng)絡(luò)抓取。我一直在關(guān)注本教程并閱讀 BS4 文檔,但我不明白為什么我的代碼不起作用。我正在嘗試使用 webscraper提取這篇文章的標(biāo)題,但它似乎找不到任何與“('div', class_='header')”匹配的標(biāo)簽我的代碼:import requestsfrom bs4 import BeautifulSoupSOURCE = requests.get('http://coreyms.com/').textSOUP = BeautifulSoup('SOURCE', 'lxml')HEADER = SOUP.find('div', class_='header')HEADLINE = HEADER.h2.a.hrefprint(HEADLINE)錯誤信息:Traceback (most recent call last): File "WSCoreySchafer.py", line 10, in <module> HEADLINE = ARTICLE.h2.a.hrefAttributeError: 'NoneType' object has no attribute 'h2'
添加回答
舉報
0/150
提交
取消