Questions tagged [urlopen]

The urlopen is a method of the urllib library in Python, used to open a particular URL.

The urlopen is a method of the urllib library in Python, used to open a particular URL. As a result, a file-like object is returned that contains information about the URL - headers, response data and other details about the requested URL resource.

369 questions
2
votes
1 answer

Python 3.6 urllib why line starts with b

I am using python 3, and don't understand why the output has b in each start of the line. I don't think this is the case for python 2. Why is this and how to remove it? Thanks import urllib # fhand =…
Ogre Magi
  • 1,445
  • 3
  • 13
  • 14
2
votes
1 answer

Why urllib2.urlopen can not open pages like "http://localhost/new-post#comment-29"?

I'm curious, how come I get 404 error running this line: urllib2.urlopen("http://localhost/new-post#comment-29") While everything works fine surfing http://localhost/new-post#comment-29 in any browser... urlopen method does not parse urls with "#"…
Shane
  • 4,875
  • 12
  • 49
  • 87
2
votes
1 answer

urlopen works in Python 2.7 but fails in Python 3.4

I have both Python 2.7.10 and Python 3.4.4 running on my computer. The following code works in Python 2.7.10: import urllib2 print urllib2.urlopen('http://google.com').read() However, if I move on to Python 3.4.4 and run import…
Lucius Silanus
  • 139
  • 1
  • 11
2
votes
1 answer

urlopen is very slow in the second call

I use urllib.urlopen() in a function called urlopen_test(). In this function I call urlopen twice,the first call is quite fast but not the second one. Anyone call help me figure out why? BTW, I use line_profile inspect every line in the function,…
fireboy
  • 29
  • 5
2
votes
1 answer

Website opens in the browser but return 403 when opened in Python

There is a website which happily opens in a browser and returns a 403 HTTP error when opened in Python as follows: from bs4 import BeautifulSoup import urllib2 link = 'http://niezalezna.pl/' r = urllib2.urlopen(link).read() soup = BeautifulSoup(r,…
tsotsi
  • 683
  • 2
  • 8
  • 20
2
votes
0 answers

sslv3 alert handshake failure (_ssl.c:645)>

Here is my code: import urllib.request try: url = 'https://bitinfocharts.com/comparison/hashrate-btc-dash-sma90.html' # now, with the below headers, we defined ourselves as a simpleton who is # still using internet explorer. headers = {} …
Tzu Chiang
  • 21
  • 3
2
votes
1 answer

Urlretrieve give local_file name from a variable

I have a really irritating problem. I'm using Python to open a URL link which is a pdf file and i want to save it in my local folder. My code : urlPath = 'http://example.com/test.pdf' myFile = urlopen(urlPath) urllib.urlretrieve(myFile.url,…
Panos Angelopoulos
  • 525
  • 1
  • 6
  • 14
2
votes
2 answers

Python urllib.request.urlopen() returning error 403

I'm trying to download the HTML of a page (http://www.guangxindai.com in this case) but I'm getting back an error 403. Here is my code: import urllib.request opener = urllib.request.build_opener() opener.addheaders = [('User-agent',…
zhangzhai
  • 21
  • 1
  • 4
2
votes
2 answers

Error on read gzip csv from url in Python: "_csv.Error: line contains NULL byte"

I am trying to read a gzipped csv file from a url. This is a very big file with more than 50.000 lines. When I try the code below I get an error: _csv.Error: line contains NULL byte import csv import urllib2 url =…
biancamihai
  • 961
  • 6
  • 14
2
votes
1 answer

Login to a website using python

I am trying to login to this page using Python.Here is my code from urllib2 import urlopen from bs4 import BeautifulSoup import requests import sys URL= 'http://coe2.annauniv.edu/result/index.php' soup =…
Emil George James
  • 1,181
  • 1
  • 10
  • 20
2
votes
2 answers

Python - merging many url's and parsing them

Below is script that I found on forum, and it is almost exactly what I need except I need to read like 30 different url's and print them all together.I have tried few options but script just breaks. How can I merge all 30's urls, parse, and than…
horse
  • 31
  • 1
2
votes
1 answer

Fast expansion of shortened URLs using python

I am writing Python code to expand shortened URLs fetched from Twitter. I have fetched all the URLs and stored them in a text file separated by a newline. Currently I am using: response = urllib2.urlopen(url) return response.url to expand…
2
votes
1 answer

urllib.request.urlopen(url) how to use this function with ip address?

I'm working on Python3 with testing page load times so I created a local apache server for compare but the problem is I use urllib.request.urlopen(url) function which doesn't allow me to use my own ip address. Is there anything that helps me to get…
Turquase
  • 83
  • 1
  • 12
2
votes
3 answers

with urllib urlopen read function but get none

[https://tools.usps.com/go/TrackConfirmAction.action?tRef=fullpage&tLc=1&text28777=&tLabels=LN594080445CN] import urllib url='https://tools.usps.com/go/TrackConfirmAction.action?tRef=fullpage&tLc=1&text28777=&tLabels=LN594080445CN' …
Roger
  • 85
  • 1
  • 9
2
votes
2 answers

Python urllib2.urlopen returns a HTTP error 503

Here you can see my code snippet. Since 3 days it does not work any longer. My python is running under Ubuntu 10.04.4 LTS. Python version is 2.6.5. #!/usr/bin/env python import urllib2 as ur ... webpage = [] site =…
DDS Boletus
  • 23
  • 1
  • 3