python selenium查詢網頁內容

zhusongziye發表於2017-09-06


# coding=utf-8
from selenium import webdriver
import time
import requests
from bs4 import BeautifulSoup as bs

driver = webdriver.Firefox()
url = "http://china.huanqiu.com/article/2016-07/9132061.html?from=bdwz"
driver.get(url)

response = bs(requests.get(url).content, 'html.parser')

# 獲取頁面內,h1標籤的文章標題

print(u"這篇文章的標題是:", response.h1.string)

# 使用find方法,尋找頁面內name=source的content的內容

print (u"這篇文章的型別是:", response.find(attrs={'name': 'source'})['content'])

# 從find_all返回的列表中,查詢content欄位

for content in response.find_all('meta', {'name': 'source'}):
    print(u"這篇文章的型別是:", content['content'])


相關文章