Ⅰ python爬蟲怎麼獲取到的網站的所有url
首先我們可以先獲取要下載圖片的整個頁面信息。
getjpg.py
#coding=utf-8
import urllib
def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html
print html
Urllib 模塊提供了讀取web頁面數據的介面,我們可以像讀取本地文件一樣讀取www和ftp上的數據。首先,我們定義了一個getHtml()函數:
urllib.urlopen()方法用於打開一個URL地址。
read()方法用於讀取URL上的數據,向getHtml()函數傳遞一個網址,並把整個頁面下載下來。執行程序就會把整個網頁列印輸出。
Ⅱ 如何通過python獲取到網站的所有url
可以通過正則表達式匹配出來的,網址的正則表達式:([\w-]+\.)+[\w-]+.([^a-z])(/[\w-: ./?%&=]*)?|[a-zA-Z\-\.][\w-]+.([^a-z])(/[\w-: ./?%&=]*)?
Ⅲ python 爬蟲怎麼獲取網址
初始地址是要你自己給的。
後續的地址可以通過解析網頁內容(比如 pyquery),通過屬性名提取,比如 pq(item).attr("src")
Ⅳ Python怎樣抓取當前頁面HTML內容
當然這樣子也是可以的,不過通用點的方法是用beautifulsoup庫去定位id=phoneCodestatus
Ⅳ python 能獲取當前瀏覽器內的網址嗎
如果要多瀏覽器的話,就是用win32com調用windows api , 自己針對每個瀏覽器去寫,
比如: 首先枚舉所有窗口,在裡面按瀏覽器標識找到這個窗口的handler,然後取找裡面的 地址欄控制項的handler,然後通過windows 消息取得他的內容
Ⅵ python 如何獲取url信息
importweb
defmake_text(string):
returnstring
urls=('/','tutorial')
render=web.template.render('templates/')
app=web.application(urls,globals())
my_form=web.form.Form(
web.form.Textbox('',class_='textfield',id='textfield'),
)
classtutorial:
defGET(self):
form=my_form()
returnrender.tutorial(form,"Yourtextgoeshere.")
defPOST(self):
form=my_form()
form.validates()
s=form.value['textfield']
returnmake_text(s)
if__name__=='__main__':
app.run()
Ⅶ python如何提取網頁信息
requests庫+ 正則表達式/dom庫/xpath庫等
Ⅷ python scrapy 如何獲取當前頁面url
你好,在response中有url的信息,你可用下面的代碼:
def parse(self, response):
print "URL: " + response.request.url
Ⅸ 如何用Python獲取瀏覽器中輸入的網址
請表述清楚意思,是要在網頁裡面輸入python代碼 ,然後可以看到執行結果,還是要如何 如果想實現網頁裡面輸入python代碼 ,然後可以看到執行結果,可以參看http://c.runoob.com/compile/6 這個網頁 直接在網頁輸入運行代碼
Ⅹ python怎麼獲取動態網頁鏈接
四中方法:
'''
得到當前頁面所有連接
'''
import requests
import re
from bs4 import BeautifulSoup
from lxml import etree
from selenium import webdriver
url = 'http://www.ok226.com'
r = requests.get(url)
r.encoding = 'gb2312'
# 利用 re
matchs = re.findall(r"(?<=href=\").+?(?=\")|(?<=href=\').+?(?=\')" , r.text)
for link in matchs:
print(link)
print()
# 利用 BeautifulSoup4 (DOM樹)
soup = BeautifulSoup(r.text,'lxml')
for a in soup.find_all('a'):
link = a['href']
print(link)
print()
# 利用 lxml.etree (XPath)
tree = etree.HTML(r.text)
for link in tree.xpath("//@href"):
print(link)
print()
# 利用selenium(要開瀏覽器!)
driver = webdriver.Firefox()
driver.get(url)
for link in driver.find_elements_by_tag_name("a"):
print(link.get_attribute("href"))
driver.close()