Friday, 30 October 2020

Extract URL's from a string using PHP [duplicate]

 

$string = "The text you want to filter goes here. http://google.com, https://www.youtube.com/watch?v=K_m7NEDMrV0,https://instagram.com/hellow/";

preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $string, $match);

echo "<pre>";
print_r($match[0]); 
echo "</pre>";

Thursday, 29 October 2020

【Python】美女爬虫 - 指定URL下载所有的图片

 https://www.youtube.com/watch?v=ZR9bG1RwrBc


Python學習03 利用Python下載網頁的圖片範例


 

Python---获取div标签中的文字

 

<span style="color:#000000"># -*- coding: UTF-8 -*-
import requests
import time
import re
from bs4 import BeautifulSoup
from urllib.request import urlretrieve

if __name__ == '__main__':
    list_url = []
    url = 'https://www.names.org/n/kevin/about'
    #设置请求头信息
    headers = {
        "User-Agent":"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
    }
    req = requests.get(url=url,headers=headers)
    req.encoding='utf-8'
    html=req.text
    bf = BeautifulSoup(html,'html.parser')
    targets_url_1 = bf.find_all(class_='container page-section')
    bf = BeautifulSoup(str(targets_url_1),'html.parser')
    targets_url_2 = bf.find_all(class_='name')
    
    #保存名字链接
    for each in targets_url_2:
        list_url.append(re.sub('[\t\n]',"",re.sub(r'<[^>]+>',"",str(each))))
    
    f = open('test.txt', 'w')  #首先先创建一个文件对象,打开方式为w
    for each in list_url:
        f.writelines(each)  #用readlines()方法写入文件
        f.writelines('\n')
         
    print(list_url)
     
    print('下载完成!')
          </span>

Sunday, 11 October 2020

Flutter vs React Native vs Ionic


 

Flutter Crash Course for Beginners 2020 - Build a Flutter App with Google's Flutter & Dart


 

通过HttpClient发起HTTP请求

 

Dart IO库中提供了用于发起Http请求的一些类,我们可以直接使用HttpClient来发起请求。使用HttpClient发起请求分为五步:

1 创建一个HttpClient

HttpClient httpClient = new HttpClient();
2 打开Http连接,设置请求头:
HttpClientRequest request = await httpClient.getUrl(uri);

这一步可以使用任意Http Method,如httpClient.post(...)httpClient.delete(...)等。如果包含Query参数,可以在构建uri时添加,如:

Uri uri=Uri(scheme: "https", host: "flutterchina.club", queryParameters: { "xx":"xx", "yy":"dd" });

通过HttpClientRequest可以设置请求header,如:

request.headers.add("user-agent", "test");

如果是post或put等可以携带请求体方法,可以通过HttpClientRequest对象发送request body,如:

String payload="..."; request.add(utf8.encode(payload)); //request.addStream(_inputStream); //可以直接添加输入流 

3 等待连接服务器:

HttpClientResponse response = await request.close();

这一步完成后,请求信息就已经发送给服务器了,返回一个HttpClientResponse对象,它包含响应头(header)和响应流(响应体的Stream),接下来就可以通过读取响应流来获取响应内容。

4 读取响应内容:

String responseBody = await response.transform(utf8.decoder).join();

我们通过读取响应流来获取服务器返回的数据,在读取时我们可以设置编码格式,这里是utf8。

5 请求结束,关闭HttpClient

httpClient.close();

关闭client后,通过该client发起的所有请求都会中止。

示例

我们实现一个获取百度首页html的例子


 

https://book.flutterchina.club/chapter11/http.html

 

 

 

 

 

 
 

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required.

zomok E-commerce system plan. Choose your online ordering system. No-risk 30 day free trial. Then USD 9/month. No credit card required. h...