Python3 teaches by hand
Official Python Manual
The problem
When writing crawlers in Python, I encountered an error of Urlopen:
>>> url = """https://www.google.com.hk/search?newwindow=1&safe=strict&biw=960&bih=430&noj=1&q=django&oq=django
&gs_l=serp.3...664389.664389.0.664921.1.1.0.0.0.0.0.0..0.0....0...1c..64.serp
..1.0.0.cfHP0MSxtWU
"""
... ...
<urlopen error no host given>
There are many reasons for this problem. For example, in order to prevent program access, some websites need to add headers, etc., in order to access normally, otherwise this error will be reported.
The solution
In fact, careful friends will find me above the code for elegance, with “” “” “” to continue line, and with the return to the URL path to truncate. So here’s the problem — this is the same as introducing the ‘/n’ character into the original URL string, so the path is wrong, so it won’t open!
As long as you don’t press enter, you can resume the normal use of urllib.request-open.
(Question: But how do you achieve line wrapping in this case?Just use ‘a’ + ‘b’ + ‘c’ ~)
Read More:
- Python: crawler handles strings of XML and HTML
- Simple Python crawler exercise: News crawling on sohu.com
- Python crawler: urllib.error.HTTPError : HTTP Error 404: Not Found
- Python crawler urllib.error.HTTPError : HTTP Error 418:
- This version of chromedriver only supports chrome version 92 crawler simulates the problem of Google plug-in version when the browser clicks and reports an error
- Attributeerror: ‘module’ object has no attribute ‘handlers’ — Python sub module import problem
- Solve the problem of unable to locate package python3.6 when upgrading from python3.5 to python3.6 in ubantu16.04
- Encountered a problem — Python — Python 3 uses Sqlalchemy to report an error‘
- Scrapy runs a crawler with an error importerror: cannot import name suppress
- CentOS solves the problem of modulenotfounderror when salt calls python3 script remotely, and solves the problem that PIP3 module cannot be shared by different users
- Pychar has a problem downloading module [install packages failed: installing packages: error occurred. Details…]
- Solution: PIP install MySQL Python has the following problems
- Solve the problem that TeamViewer software prompts that the trial period has expired and cannot be operated remotely
- Python problem: indenta tionError:expected an Error resolution of indented block
- Install apache2.4 on windows to solve the problem of the requested operation has failed
- Python has a bus error while importing tensorflow
- Solved! The new version of statsmodels has the problem of importerror: cannot import name ‘factorial’
- Solve the problem of “A TimThumb error has occured” in the WordPress program
- Flash back problem of Python running
- Analysis of R language error replacement has length zero problem