私は、Python、リクエスト、およびBeautifulSoupを使用してWebスクレイピングアプリケーションを構築しています。エスケープされた文字列が認識されない
ように私はクラス変数を宣言:私はprint self.TAG
を使用して、このタグを検証し、私はprint self.TAG
からの出力を得た
class myClass(object):
TAG = "\"span\",{\"data-automation\":\"jobListingDate\"}"
この文字列"span",{"data-automation":"jobListingDate"}
self.TAG
を示唆して
"span",{"data-automation":"jobListingDate"}
です
しかし、次の2行のコードでは異なる結果が得られました。
r = requests.get("someURL")
html = BeautifulSoup(r.content, "html.parser")
html.find(self.TAG) #this line does not find anything at all
html.find("span",{"data-automation":"jobListingDate"}) #this line does find what I am after
私は、self.TAG
はこの文字列"span",{"data-automation":"jobListingDate"}
と同じではありませんか、混乱しています私は適切に何を免れませんか?
html.find(self.TAG)
の場合
「自己」とは何ですか? 'html.find'とは何ですか? –
@cᴏʟᴅsᴘᴇᴇᴅ、問題解決済み。あなたのコメントをありがとう、私は最初からそれらを明確にすべきだった。 –