因此,我正在製作一個網頁「抓取工具」,用於解析網頁,然後在網頁中搜索單詞或單詞集。這裏出現了我的問題,我查找的數據包含在解析後的網頁中(我使用特定的單詞作爲測試運行它),但它表示它所查找的數據尚未找到。未找到python html解析器數據
from html.parser import HTMLParser
from urllib import *
class dataFinder(HTMLParser):
def open_webpage(self):
import urllib.request
request = urllib.request.Request('https://www.summet.com/dmsi/html/readingTheWeb.html')#Insert Webpage
response = urllib.request .urlopen(request)
web_page = response.read()
self.webpage_text = web_page.decode()
return self.webpage_text
def handle_data(self, data):
wordtofind = 'PaperBackSwap.com'
if data == wordtofind:
print('Match found:',data)
else:
print('No matches found')
p = dataFinder()
print(p.open_webpage())
p.handle_data(p.webpage_text)
我已經運行該程序沒有打開的網頁功能使用提要方法,它的工作原理和發現數據,但現在不起作用。
解決這個問題的任何幫助表示讚賞
究竟是什麼,你是從網站上提取?來自href標籤的鏈接? –
我只是試圖從頁面中找到文本,無論是在href標記還是在p標記中 – S0lo