2016年11月18日 星期五

[Crawler] Beginning: Trying urllib.request

method 1: open a File and save it in your current python Folder.
import urllib.request
page = urllib.request.urlopen("http://beans-r-us.appspot.com/prices.html")
text = page.read().decode("utf8")
print(text)
price = text[234:238];
print(price)
where = text.find('>$')
start_of_price = where + 2
end_of_price = start_of_price + 4
price = text[start_of_price : end_of_price]
print(price + " by using find command")
method 2:

type each command

import urllib.request

x = urllib.request.urlopen("http://www.google.com/")

print(x.read())

https://www.youtube.com/watch?v=5GzVNi0oTxQ


2.type line by line as below code
from urllib.request import urlopen
html = urlopen("http://www.google.com/")
print(html)
print(html.read())



http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python

reference:
[book] A Brain-Friendly Guide, Paul Barry && David Griffths
Share:

Related Posts:

0 意見:

張貼留言