Hongmu Notes
Home Practical Collection Push your website to the Bing search engine using PHP + Python
Practical Collection Utility tools

Push your website to the Bing search engine using PHP + Python

Push your website to the Bing search engine using PHP + Python

Push your website link to the Bing search engine!

Python code

import requests
import re

#根据站点地图获取链接
def get_urls(sitemap):
    response = requests.get(url=sitemap)
    urls = re.findall('<loc>(.*?)</loc>', response.text)
    return urls

#提交到必应
def submit_bing(site_url: str, url_list: list, api_key: str):
    try:
        response = requests.post(url=f"https://ssl.bing.com//webmaster/api.svc/json/SubmitUrlbatch?apikey={api_key}",
                                 json={
                                     'siteUrl': site_url,
                                     'urlList': url_list
                                 },
                                 headers={
                                     'Host': 'ssl.bing.com',
                                     'Content-Type': 'application/json; charset=utf-8',
                                 })
        print(response.status_code)
    except Exception as e:
        print('e')
    finally:
        if response.status_code == 200 and response.json().get('d') is None:
            print('推送成功:')
            for i in url_list:
                print(i)
        else:
            print('推送失败:推送配额不足,https://www.bing.com/webmasters/submiturl')

if __name__ == '__main__':
    apiKey = ''
    siteUrl = 'https://www.pbba.cn/'
    urlList = get_urls('https://www.pbba.cn/sitemap_cate_1.xml')
    submit_bing(site_url=siteUrl, url_list=urlList, api_key=apiKey)

PHP code

<?php

// 根据站点地图获取链接
function get_urls($sitemap) {
    $response = file_get_contents($sitemap);
    preg_match_all('/<loc>(.*?)<\/loc>/', $response, $matches);
    return $matches[1];
}

// 提交到必应
function submit_bing($site_url, $url_list, $api_key) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://ssl.bing.com//webmaster/api.svc/json/SubmitUrlbatch?apikey={$api_key}");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
        'siteUrl' => $site_url,
        'urlList' => $url_list
    ]));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Host: ssl.bing.com',
        'Content-Type: application/json; charset=utf-8'
    ]);

    $response = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    curl_close($ch);

    if ($http_code == 200 && json_decode($response)->d == null) {
        echo "推送成功:\n";
        foreach ($url_list as $url) {
            echo $url . "\n";
        }
    } else {
        echo "推送失败:推送配额不足,https://www.bing.com/webmasters/submiturl\n";
    }
}

$apiKey = '';
$siteUrl = 'https://www.pbba.cn/';
$urlList = get_urls('https://www.pbba.cn/sitemap_cate_1.xml');
submit_bing($siteUrl, $urlList, $apiKey);

?>
微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Practical Tool: Nginx Website Log Analysis

Practical Tool: Nginx Website Log Analysis Practical Collection Utility tools

As the name suggests, this is a simple log analysis tool that can extract specific information from your website's logs! Step 1: Place the log file and the tool in the same directory. Place the Log file (Nginx website logs) into the program's directory, or copy/move the program to the directory where the log file is located. Step 2: Modify the log file name. Change the website log file name to `rizhi.log`; otherwise, the program will fail to operate...
👁 183
ChatGPT generates articles in Markdown format.

ChatGPT generates articles in Markdown format. Practical Collection Utility tools

In the early hours of March 2, OpenAI launched the official ChatGPT API – not the underlying GPT-3.5 large-scale model, but the core ChatGPT model itself: ChatGPT-3.5-Turbo! The ChatGPT-3.5-Turbo model is the model used by ChatGPT and represents the fastest, most cost-effective, and most flexible model in the GPT-3.5 series. It can deliver ultra-high...
👁 223
Python converts Markdown to HTML.

Python converts Markdown to HTML. Practical Collection Utility tools

Python converts Markdown to HTML; the file format can be configured. After running the script, two directories – `md` and `html` – will be automatically created. Files to be converted should be placed in the `md` directory; the converted files will then be placed in the `html` directory! The software generates a log file, which you can review to see the details of the conversion process! To view the converted output, check the original Markdown: < < < Title: PHP Function for Removing Duplicates from Two-Dimensional Arrays...
👁 171
MSVBCRT.AIO.2019.10.19.X86/X64 (Microsoft Common Runtime Library Collection)

MSVBCRT.AIO.2019.10.19.X86/X64 (Microsoft Common Runtime Library Collection) Practical Collection Utility tools

Software for resolving DLL-related computer software errors: On Windows systems where official drivers (e.g., Microsoft Visual Studio 2015) are not fully installed, installing certain software may trigger an error message stating that a specific DLL file is missing and prevents the software from launching. This software package can resolve this issue; it is compatible with Windows 7, 8, 8.1, 10, and 11 operating systems.
👁 467
A simple yet powerful HTML code snippet – iFearMe Framework

A simple yet powerful HTML code snippet – iFearMe Framework Summary of pitfalls Practical Collection Utility tools

Since I prefer automation when building websites, many tasks require multiple visits to a single URL to process content stored on the server. In such cases, for various reasons, it may not be possible to simply refresh the page directly; this is where the iFearMe framework comes in handy! The iFearMe framework code: <!DOCTYPE html> <html> <head> <title...
👁 212
Online LRC to STR converter/Base64 decoding tool – implemented using HTML and jQuery

Online LRC to STR converter/Base64 decoding tool – implemented using HTML and jQuery Summary of pitfalls Practical Collection Website source code Utility tools

A very useful web application designed primarily to convert LRC lyric files to STR subtitle format, along with a Base64 decoding tool. Main Features: 1. LRC to STR Converter – Input: Users can paste LRC lyrics or upload an LRC file; Conversion: Click the "Convert to STR" button to convert the LRC file to STR format; Output: The converted STR subtitles are displayed; these can be downloaded or saved. 2. Base64 Decoding Tool...
👁 215

Recommended reading

Responsive Healthcare Technology Medical Device Website Template 0344

Responsive Healthcare Technology Medical Device Website Template 0344 Practical Collection Yiyou template

An eYouCMS responsive website template designed for the medical technology and medical device industries. Its professional, tech-oriented design effectively showcases medical device products, technological R&D initiatives, clinical applications, and corporate strength. This template helps medical technology companies showcase their brands online and attract hospitals and distributor clients. Template Overview | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: eYouCMS Installation Guide...
👁 53
WordPress issue: pages freezing due to image transcoding

WordPress issue: pages freezing due to image transcoding Program Notes wordpress

Last night, while uploading an image, for some reason, the uploaded image was automatically transcoded. Transcoding type: BASE64 encoding. For an image on a website, simply upload it to your server and then access the link – the image will then be displayed. However, there is another approach: directly transcoding the image; then you can simply access the converted image using its encoded URL. Problem description: When an image is relatively small (e.g., only a few KB in size), transcoding it and then hosting it on a website can help avoid...
👁 152
Fresh Fruit Picking Garden Rural Tourism Website Template 1206

Fresh Fruit Picking Garden Rural Tourism Website Template 1206 Practical Collection Yiyou template

An eYouCMS website template designed for fresh fruit picking farms and rural agritourism businesses. Its fresh and natural design effectively showcases the orchard environment, picking experiences, rural characteristics, and leisure tourism services. This template helps agritourism businesses attract online visitors and enhance their brand awareness. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for eYouCMS | eYouCMS (...
👁 60
(Adaptive mobile version) Responsive web development software – Mini-program development – Websites – PBootCMS template 0683

(Adaptive mobile version) Responsive web development software – Mini-program development – Websites – PBootCMS template 0683 Practical Collection pbootcms Template

A responsive website and software development mini-program template based on PbootCMS, compatible with both PC and WAP devices. Featuring a modern, tech-oriented design, this template is ideal for IT service companies and software development teams to showcase their projects and technical expertise. It helps technology firms attract potential clients seeking development services online. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www...
👁 50
Project Construction and Decoration Engineering Enterprise Website Template 0345

Project Construction and Decoration Engineering Enterprise Website Template 0345 Practical Collection Yiyou template

This EyouCMS template is ideal for construction and decoration engineering firms, featuring a professional architectural design style that effectively showcases decoration projects, construction case studies, design expertise, and corporate image. It helps decoration companies present their brand online and attract developers and property owners. Template Display | Installation Instructions | Website Backend: /login.php | Username: admin | Password: admin | Related Articles: Summary of Common Installation Issues for EyouCMS | Eyou...
👁 52
5118 Pet Industry Vocabulary Database (230 MB)

5118 Pet Industry Vocabulary Database (230 MB) Practical Collection SEO vocabulary

Building a website requires a keyword database – do you understand? Here, we've compiled a keyword database specifically for the pet industry; this database can be utilized when creating a website focused on the pet industry. Keyword database file display: Source information: Pet industry keyword database – Data source: https://www.5118.com/ciku/detail/64?promote=F5834D [Note]: This industry-specific keyword database includes high-frequency terms, interrogative words, and industry-related terms...
👁 183