requests is a very useful Python HTTP client library , writing crawlers and test server response data is often used. It can be said that Requests fully meet the needs of today's network. This article focuses on the use of python requests module to achieve crawling movie heaven the latest movie information, the specific content is as follows:
When crawling the web data, sometimes the structured data is extracted with a regular, such as href="https://", etc. The findall() function of python's re module returns a list of all matches. The list datatype is not allowed when storing data into a database, but rather needs to be converted to a tuple. See below, str/list/tuple three how to convert each other.
class forDatas: def __init__(self): pass def str_list_tuple(self): s = 'abcde12345' print('s:', s, type(s)) # str to list l = list(s) print('l:', l, type(l)) # str to tuple t = tuple(s) print('t:', t, type(t)) # str into list/tuple, just do the conversion directly # Convert from list/tuple to str with the help of the join() function. # list to str s1 = ''.join(l) print('s1:', s1, type(s1)) # tuple to str s2 = ''.join(t) print('s2:', s2, type(s2))
str into list/tuple, direct conversion can be done. And by list/tuple conversion to str, you need to use the join () function to achieve. join () function is described in this way:
""" (iterable) -> str Return a string which is the concatenation of the strings in the iterable. The separator between elements is S. """
The join() function is used by passing in an iterable object and returning an iterable string with an "S" separator between the string elements.
Pass in an iterable object, which can make a list, a tuple, or a str.
s = 'asdf1234' sss = '@'.join(s) print(type(sss), sss)
summarize
The above is a small introduction to the python using requests module to achieve the crawl movie heaven the latest movie information, I hope to help you, if you have any questions please leave me a message, I will promptly reply to you. Here also thank you very much for your support of my website!