我使用mechanize
庫登錄網站。我查過了,效果很好。但問題是我不能使用response.read()
與BeautifulSoup
和'lxml'。爲什麼BeautifulSoup和lxml不起作用?
#BeautifulSoup
response = browser.open(url)
source = response.read()
soup = BeautifulSoup(source) #source.txt doesn't work either
for link in soup.findAll('a', {'class':'someClass'}):
some_list.add(link)
這不起作用,實際上沒有找到任何標籤。它適用於我使用requests.get(url)
。
#lxml->html
response = browser.open(url)
source = response.read()
tree = html.fromstring(source) #souce.txt doesn't work either
print tree.text
like_pages = buyers = tree.xpath('//a[@class="UFINoWrap"]') #/text() doesn't work either
print like_pages
不打印任何東西。我知道它的退貨類型爲response
,因爲它與requests.open()
配合良好。我能做什麼?您能否提供示例代碼,其中response.read()
用於html解析?
順便說一下,response
和requests
對象有什麼區別?
謝謝!